How the EPUB to PDF Converter Works
AnyTool EPUB to PDF reads an e-book entirely in the browser with JSZip and builds the PDF with pdf-lib, both bundled into the app and served from the same origin — never loaded from a CDN — so the tool stays fully offline-capable and uploads nothing. An EPUB is a ZIP of XHTML, CSS and packaging files, so the engine first reads META-INF/container.xml to locate the OPF package document, then parses it with DOMParser: the <metadata> yields the title, creator (author) and language; the <manifest> maps every resource id to its href and media-type; and the <spine> gives the linear reading order as a sequence of itemref → idref entries, with hrefs resolved relative to the OPF folder. Each spine document (an XHTML chapter) is parsed and flattened into an ordered block list — headings (h1–h6), paragraphs, bulleted and numbered list items, blockquotes, preformatted code, horizontal rules and images — with scripts and styles stripped, HTML entities decoded and whitespace normalized. <img> sources are resolved against the manifest, the bytes pulled from the ZIP, and JPEG/PNG images embedded. pdf-lib then lays the blocks onto pages: standard fonts (Helvetica, bold, oblique and Courier for code) are embedded, text is word-wrapped to the content width using font.widthOfTextAtSize and advanced by a line height, and a new page is started when the cursor passes the bottom margin. Headings are sized by level, lists get a hanging indent, blockquotes a left bar, images are scaled to fit, and an optional title page, footer page numbers and a clickable chapter outline are added.
- EPUB unzipped with JSZip; PDF built with pdf-lib — both bundled, no CDN
- Reading order recovered from container.xml → OPF → spine (itemref/idref)
- XHTML flattened to headings, paragraphs, lists, quotes, code and images
- Word-wrap via font.widthOfTextAtSize with line-height pagination
- JPEG/PNG images embedded (embedJpg/embedPng) and scaled to fit
