Glossary

EPUB

An open ebook format that packages a book as a ZIP of XHTML chapters, CSS, images and XML metadata, so the text can reflow to fit any screen.

An EPUB file is an ebook packaged as a ZIP archive of XHTML pages, CSS, images and XML metadata, built to an open standard so the text can reflow to fit any screen. Where a PDF fixes every line to a position on a page, an EPUB stores the book as structured web content, and the reading app lays it out on the fly for the reader’s device, font size and preferences. The standard is maintained by the W3C, having previously been developed by the International Digital Publishing Forum, and it is the format most ebook stores, libraries and publishers use to distribute books.

What is inside an EPUB file

Rename an EPUB to .zip and unzip it, and the structure is easy to follow. The first entry in the archive is a small file called mimetype containing the string application/epub+zip, stored uncompressed so that file type detection can identify the book from its first bytes without unpacking anything. A META-INF folder holds container.xml, which points to the package document, usually named content.opf. Everything else, the chapters, stylesheets, fonts and images, sits in a content folder that the package document describes.

The package document is the book’s manifest. Its metadata section records the title, author, language, unique identifier (often an ISBN or a UUID), publisher and modification date, using Dublin Core elements. Its manifest lists every resource in the archive along with its MIME type. Its spine gives the linear reading order: the sequence of XHTML files a reader moves through from the first page to the last. A separate navigation document, nav.xhtml in EPUB 3 or toc.ncx in EPUB 2, provides the table of contents that reading apps show as chapter links.

The chapters themselves are XHTML, the XML-strict form of HTML, styled with CSS. That makes an EPUB closer to a small offline website than to a word-processing file. Headings are real h1 and h2 elements, paragraphs are p elements, footnotes are links between files, and images are referenced with img tags. EPUB 3 added HTML5 elements, embedded audio and video, MathML for equations, SVG graphics, scripting in some reading systems, and media overlays that synchronise recorded narration with the text.

EPUB 2, EPUB 3 and fixed layout

Most files in circulation are EPUB 2 or EPUB 3. EPUB 2, from 2007 with a revision in 2010, used XHTML 1.1, an NCX table of contents and a narrower feature set. EPUB 3, first published in 2011 and now maintained by the W3C as EPUB 3.3, moved to HTML5, replaced the NCX with an HTML navigation document, and added accessibility metadata, semantic markup for structures such as footnotes and glossaries, and better support for non-Latin scripts and vertical writing. Reading apps generally open both, and many older books are still EPUB 2.

Reflowable layout is the default, but a fixed-layout EPUB is also possible. Each page is an XHTML file with set dimensions and absolutely positioned elements, which suits picture books, comics, cookbooks and some textbooks where the design depends on placement. Fixed-layout books are harder to process than reflowable ones, because the logical reading order follows coordinates on the page rather than the order of the markup. That brings back the same problems that make slide decks and PDFs awkward to extract.

Digital rights management is a separate layer on top. Many commercial EPUBs are encrypted by the store that sold them, using Adobe’s scheme or a vendor’s own. An encrypted EPUB keeps its ZIP structure and its readable metadata, but the chapter files are ciphertext that only an authorised reading system can open. Any pipeline that ingests EPUBs should check for an encryption.xml file in META-INF and flag those books, rather than indexing garbled text.

EPUB compared with PDF, DOCX and Markdown

EPUB sits between a web page and a document format. The table compares it with the formats it is most often converted to or from.

Format

Layout

Structure

Typical use

Ease of extraction

EPUB

Reflows to the screen

XHTML chapters, spine, navigation document

Ebooks and long-form reading

High for reflowable books, lower for fixed layout

PDF

Fixed pages

Positioned text and graphics

Print, forms, archiving

Varies with the text layer and layout

DOCX

Reflows in an editor

XML paragraphs, styles and tables

Editing and collaboration

High to medium

Markdown

Plain text

Headings, lists, links

Notes, documentation, LLM input

Very high

The practical difference for software is that EPUB keeps semantics a PDF throws away. In PDF parsing, a heading has to be inferred from font size and position; in an EPUB it is already marked as a heading. Lists are lists, tables are table elements, and the chapter order is written down in the spine. A DOCX file preserves similar structure in Word’s own XML vocabulary, and Markdown keeps the lightest structure in plain text. When a publisher holds both a PDF and an EPUB of the same title, the EPUB is usually the cleaner source for any text processing. The wider trade-off between editable and fixed formats is covered in DOCX vs PDF.

How to extract text from an EPUB

Because the content is XHTML, extracting text from an EPUB is mostly HTML parsing with a few extra steps. A reliable process opens the archive, reads container.xml to find the package document, parses the package for metadata and the spine, then walks the spine in order, parsing each XHTML file and collecting its text. Following the spine matters because the order of files inside the ZIP is arbitrary, and some books list covers, front matter or appendices in the manifest as non-linear items that should be handled separately from the main text.

Within each chapter, the job looks like HTML to Markdown conversion. Headings become heading markers, paragraphs become blocks, emphasis is kept or dropped depending on the destination, and tables, lists and footnotes are carried across. Navigation elements, page-list markers and repeated running heads are the ebook equivalent of web page clutter, and a light pass of boilerplate removal keeps them out of the text. Images need their own decision: keep their alt text and captions, or run OCR and image captioning on them when they carry information such as charts or scanned tables.

Metadata is the easy part. Title, creator, language, identifier, publisher, subjects and dates sit in the package document in a predictable form, which makes EPUB one of the friendlier formats for metadata extraction. EPUB 3 accessibility metadata, such as whether images have alternative text or whether a page list maps the ebook to a print edition, sits alongside it and is worth keeping when the text will be cited by page.

A few edge cases come up often enough to plan for. Some files are malformed ZIPs produced by older conversion tools. Some declare the wrong character encoding. Some split a single chapter across several XHTML files, while others put the whole book into one very large file. Some use CSS to hide or reorder content in ways a plain text extractor will not see. Footnotes may be pop-up asides at the end of each chapter file or collected in a separate notes file, and a careful extractor resolves those links so each note stays attached to the passage that cites it.

Preparing EPUBs for search and RAG

Ebooks are long, so they almost always need splitting before an AI system can use them. Chunking by chapter and section follows the author’s own structure, which an EPUB makes explicit, and tends to produce more coherent passages than fixed-size windows over a PDF. Each chunk should keep its chapter title and position in the spine so an answer can say where in the book it came from. That location data is what makes source attribution possible in a RAG system: a reference to chapter 7, section 2 is a citation a reader can check.

From there the usual data ingestion steps apply: embeddings for semantic search, keyword indexes for names and terms, and metadata filters on author, language or subject. A library of a few hundred books can run to tens of millions of tokens, far beyond any context window, so retrieval quality decides whether an assistant built on that library finds the right passage. Returning the specific paragraph rather than the whole chapter matters more for books than for short documents, because a single chapter can run to several thousand words. Sub-document retrieval explains how that works.

The format of the converted text also affects cost and accuracy. Markdown keeps headings and emphasis in very few tokens, while JSON suits pipelines where each chunk needs fields such as chapter, position and book identifier. JSON vs Markdown for LLMs compares the two in more detail.

Where EPUB shows up in AI products

Publishing, education and research are the main sources. A publishing house building an assistant over its backlist will often hold EPUBs for every title released in the last fifteen years. An education platform may store course texts as EPUB, and a learning copilot needs to quote from them accurately. Research teams collecting book-length reports meet EPUBs alongside PDFs and Word files, and personal knowledge tools let users upload their own DRM-free ebooks and ask questions about them.

In each case the EPUB is a source format rather than the format the AI works with. The book has to be unpacked, cleaned, split and indexed before it is useful, and kept current when a new edition replaces an old one. That ongoing work is a knowledge base problem as much as a parsing problem, and it is one reason the post on which file types AI apps ingest treats ebooks as a format worth planning for from the start.

How Exabase handles EPUB files

Exabase provides the infrastructure around ebook ingestion rather than a reading app. The EPUB to JSON and EPUB to Markdown tools convert a book into structured output an agent or pipeline can work with, alongside equivalent converters such as DOCX to JSON and PDF to JSON. For files of every type, Extract is the general entry point: one POST /v2/extract endpoint handles documents, images, audio, video and web pages, returns text as chunks with page numbers or timestamps, and runs asynchronously with polling or webhooks. The submitting jobs guide covers the request format.

Once the text is out, Resources stores it in a Base, where it is indexed as it is written, and Deep Search searches inside it at the sub-document level, combining semantic and keyword matching with a precision setting per query. Bases keep each customer’s or project’s library isolated from every other, and a Worker can re-process a title on a schedule when a new edition arrives, so the index reflects the current text. The file extraction and knowledge base solution pages describe those patterns in full.

Exabase is the substrate in this picture. Deciding which books to ingest, how to handle DRM-protected titles and what an assistant should do with the passages it retrieves stays with the application built on top. For a wider view of tools that convert documents into structured data, see the best document extraction APIs.

Frequently asked questions

Is an EPUB just a ZIP file?

Yes, with a required structure. An EPUB is a ZIP archive that starts with an uncompressed mimetype file, contains META-INF/container.xml pointing to the package document, and holds XHTML chapters, CSS, images and fonts as content. Renaming it to .zip lets any archive tool open it.

What is the MIME type of an EPUB file?

The MIME type is application/epub+zip. The same string is stored in the mimetype file at the start of the archive, which lets software identify an EPUB without relying on the .epub extension.

Do EPUB files need OCR?

Usually not. Reflowable EPUBs contain real text in XHTML, so it can be read directly. OCR is only needed for text inside images, such as charts, scanned plates or fixed-layout books built from page images.

Can an EPUB be converted to Markdown without losing structure?

Mostly, yes. Headings, lists, links and emphasis carry over well because the source is already structured HTML. Complex tables, footnotes and fixed-layout pages lose the most and are worth checking after conversion.

Can AI tools read DRM-protected EPUBs?

No, not without the decryption keys a licensed reading system holds. Encrypted chapter files appear as ciphertext, so ingestion pipelines should detect encryption.xml in META-INF and skip or flag those books.

How should an EPUB be chunked for RAG?

By its own structure first: chapters, then section headings, with a size limit so very long sections are split further. Keep the chapter title and spine position on every chunk so answers can cite their source.

Is EPUB or PDF better for AI ingestion?

EPUB, when both exist. It keeps headings, reading order and lists as markup, while a PDF stores positioned text that has to be reassembled. Extract handles PDFs when an EPUB is not available.

Related pages: DOCX, PPTX, Markdown, MIME type, file type detection, metadata extraction, PDF parsing, HTML to Markdown, EPUB to JSON, file extraction

Cut your token spend and give your agent precise context.

Get started in minutes.

Cut your token spend and give your agent precise context.

Get started in minutes.