WebTools

307 Useful Tools & Utilities to make life easier.

EPUB to PDF Converter

Convert complex e-Reader EPUB archives into universally readable PDF document formats.

Unpack and compile robust .epub archives natively into scalable PDF documents (Max: 20MB)

How Does the EPUB to PDF Converter Work?

This tool seamlessly transforms your electronic publications into unified, beautifully rendered PDF documents natively on the server. Because EPUB files are essentially a bundled package of structured HTML, XML, and style files, converting them natively requires parsing their internal architecture, compiling the chapters sequentially, and rendering them as a single document.

The converter utilizes PHP's built-in ZipArchive library to deeply explore the EPUB file format. Once uploaded, the process begins by locating the rootfile nested within the archive at META-INF/container.xml. This file holds the crucial full-path attribute, pointing directly to the OPF (Open Packaging Format) core manifest file.

Using memory-efficient regular expressions, the engine maps all manifest nodes and reading spine sequences. The reading spine dictates the exact sequential order of the book's chapters by matching itemref nodes to their corresponding file paths. The system traverses this spine to fetch each individual HTML or XHTML chapter directly out of the zip archive. Finally, the stitched content is processed by the robust Dompdf library. The engine leverages an HTML5 parser to securely build the visual flow onto standard A4 Portrait pages using the Helvetica font.

Intelligent Tag Stripping and Page Management

Because EPUB documents can contain incredibly complex (and sometimes messy) proprietary CSS and layout tags, passing raw HTML directly into a PDF engine often leads to formatting disasters. To prevent this, the compiler aggressively strips out advanced styling and non-essential DOM elements. It cleanly preserves only a strict subset of essential structural HTML nodes:

  • Headings (<h1> through <h6>)
  • Paragraphs (<p>) and Line Breaks (<br>)
  • Text Emphasis (<b>, <i>, <strong>, <em>)
  • Lists (<ul>, <ol>, <li>)
  • Containers and Quotes (<blockquote>, <span>, <div>)

Furthermore, the compiler automatically filters out "ghost" pages. If a chapter file only contains non-breaking spaces (&nbsp; or &#160;) or hidden structural tags without readable text, the algorithm skips it completely to prevent blank pages from bloating your final PDF. Every valid chapter is subsequently wrapped in a container that forces a page-break-after: always; rule, ensuring chapters start neatly on fresh pages.

Concrete Worked Example

Consider an uploaded EPUB archive containing three chapters mapped in the OPF spine: cover.html, blank-page.html, and chapter1.html.

cover.html contains: <div class="cover"><h1>My Book</h1><img src="cover.jpg"></div>
blank-page.html contains: <p>&nbsp;</p><div class="spacer"></div>
chapter1.html contains: <h2>Chapter 1</h2><p>It was a dark and stormy night...</p>

Expected Output Process:

  1. Spine 1 (cover.html): The engine strips the unsupported <img> tag and the class attributes. It evaluates the remaining text ("My Book") and determines it is not empty. The content is appended to the PDF structure with a forced page break.
  2. Spine 2 (blank-page.html): The &nbsp; entity and formatting tags are stripped. The remaining plain text is entirely empty. The engine skips this file, preventing a blank page in the output.
  3. Spine 3 (chapter1.html): The heading and paragraph text are preserved. The content is cleanly injected into the master HTML template.

The final compilation is sent to Dompdf, generating a crisp 2-page document downloaded as [original-filename].pdf.

Technical Limitations and Constraints

  • File Size Limit: Archives are strictly capped at 20 Megabytes (20MB). Uploading larger files will trigger validation errors.
  • File Extension: The system enforces a strict check on the .epub extension. Other ebook formats (like MOBI or AZW3) will throw an "Invalid file type architecture block" error.
  • Font and Sizing: PDF output is permanently hardcoded to use the Helvetica font family and an A4-sized portrait orientation.
  • Image Stripping: Because image tags (<img>) are not included in the allowed tag whitelist, all images, including cover art, are removed during the conversion. Only textual content and structural formatting survive the compilation.

Frequently Asked Questions

Why are images missing from my PDF?

To ensure perfect pagination and layout stability across complex Dompdf renderings, the conversion engine actively strips all image tags during the extraction phase. The compiler only whitelist-preserves text-formatting tags, meaning your final PDF focuses purely on the written content.

Why did my PDF output have fewer pages than my EPUB's chapter count?

The system features a "ghost page" detector. During compilation, the script strips all HTML tags and invisible entities (like &nbsp; and &#160;) from every chapter file. If a chapter file holds zero readable plain text, the engine skips it to avoid printing blank pages. This commonly removes empty dedication pages or layout-spacer files present in the original EPUB.

What happens if the EPUB is malformed?

The compiler specifically looks for a valid META-INF/container.xml file pointing to an OPF manifest. If these foundational architectural files are missing or heavily corrupted, the tool immediately halts execution and returns a "Structural Error" warning rather than generating a broken PDF.

Does this tool support external CSS from the EPUB?

No. To guarantee reliable A4 printing formats, external CSS rules from the EPUB archive are discarded. The tool instead injects a clean, universal stylesheet featuring justified text, 1.6 line heights, and a standardized dark-gray text color on a white background.

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us