DRM-free Kindle books · MOBI 6, KF8 (AZW3) and combo files · edit the metadata before you save

MOBI and AZW3 to EPUB

Convert a Kindle book you own without DRM into an EPUB 3 that other readers open. The page rebuilds the pages, stylesheet, images, fonts and contents list, and refuses a book that is protected.

1. The book

Choose a .mobi, .azw3 or .azw file

Up to 100 MB; DRM-protected books are refused

MOBI and AZW3 to EPUB

Operator: Abdulla Al Fahad. How tools are built and checked

Kindle books come in three shapes that look alike on disk: old MOBI 6 files, which hold one long stream of HTML-like markup, AZW3 or KF8 files, which store a skeleton of pages with fragments slotted into it, and combo files that carry both. Other e-readers and publishing tools want EPUB, which is a ZIP of clean XHTML.

All three are read, the pages are rebuilt from the Kindle indexes, every Kindle-internal link is mapped to an EPUB path, and EPUB 3 is written with a contents list. Check the book's source first: only books without DRM can be converted, and a protected book is refused with an explanation, not worked around.

Key features

  • MOBI 6, KF8 (AZW3) and combo files, with PalmDOC LZ77 and HUFF/CDIC text compression
  • KF8 pages rebuilt from the skeleton and fragment indexes, with the flow table splitting stylesheets and SVG from the page text
  • Kindle-internal links (kindle:pos, kindle:embed, kindle:flow) rewritten to ordinary EPUB paths, with an id added to each link target
  • The contents list rebuilt from the NCX index, nested by heading level, in both an EPUB 3 navigation document and an EPUB 2 NCX
  • Title, authors, publisher, language, identifier, subjects, date, description and cover read from the EXTH header, all editable before you save
  • Embedded fonts un-obfuscated and inflated, and images detected by their first bytes rather than trusted by number

How Kindle files are read and what the EPUB contains

The file is a Palm database. Record 0 holds a PalmDOC header, then the MOBI header, then an EXTH block of numbered metadata records: 100 is the author, 101 the publisher, 201 the offset of the cover image, 524 the language and 121 the record where the KF8 half of a combo file starts. Text records follow, each compressed on its own with up to several trailing entries that the extra-data flags announce, which have to be trimmed before decompression.

In a KF8 book the text is a skeleton per page plus fragments stored behind it. The skeleton index gives each page's start and length. The fragment index gives, for each piece, where it belongs inside its skeleton and how long it is. Putting the pieces together gives the XHTML. The flow table (FDST) then divides the whole text into the page flow and the stylesheets or SVG that pages refer to.

Links are base-32 coordinates. A reference such as kindle:pos:fid:0003:off:0000000000 names fragment number 3 and an offset inside it. The page converts that to a position in a page, finds the element that starts there and uses its id, or the Kindle aid attribute, or makes one up, then rewrites the href to part0002.xhtml#that-id.

A MOBI 6 book is different: links are byte offsets into the text (filepos), pages are separated by mbp:pagebreak markers, and images are numbered records. The markup is repaired into XHTML, an anchor is placed at each linked offset, and short sections between page breaks are merged so the EPUB does not end up with hundreds of tiny files.

How it works

Everything runs in one pass in your browser. Text is decompressed record by record, the indexes are parsed into entries (each with tag values stored as variable-width integers), and the book is assembled in memory with a 160 MB cap on the decompressed text and 100 MB on the input file. The EPUB is then zipped with the mimetype entry first and uncompressed, as the format requires.

Common use cases

  • An author whose publishing tool exported a DRM-free AZW3 needs an EPUB for a library platform. She converts it, fixes the language from en to en-GB in the metadata panel, and uploads the result.
  • A reader has a MOBI 6 handbook that his reader cannot open. The converted EPUB keeps every entry of its contents list and the links behind them.

How to use this tool

  1. Choose the .mobi, .azw3 or .azw file; the page reads it at once and states whether it is protected.
  2. Check the counts and the contents list, then correct the title, authors, language or identifier if the header had them wrong.
  3. Press Download EPUB.

Example

Alice's Adventures in Wonderland from Standard Ebooks (AZW3, 5,828,393 bytes, KF8)

Open the file; keep the metadata as read; download

Counts and the saved EPUB

KF8 (AZW3), 21 pages, 45 images, 2 stylesheets, 20 contents entries, 43 internal links rewritten, none lost. The EPUB is about 5.76 MB. Its text has 28,299 words against 28,298 in Standard Ebooks' EPUB of the same book; the extra word is a stray x that sits in the Kindle file's frontispiece.

Tips for best results

  • A combo file contains both a MOBI 6 and a KF8 version of the book. The page uses the KF8 half, which has the better markup and styles.
  • Fill in the language before saving if the header had none; readers use it for hyphenation and text-to-speech voice.
  • Check the contents list entry count against what you expect. A book whose NCX is damaged converts but gets a one-entry contents list, and the notes say so.
  • The EPUB identifier comes from the ISBN, else the ASIN, else a random UUID. Keep an existing one if the book is already catalogued.

Edge cases to watch

Layout is reflowable only. Fixed-layout and comic-style Kindle books, and Kindle's newer KFX format, are not supported.

Audio, video and Kindle-specific interactive features are left out; the EPUB holds text, images, fonts, stylesheets and SVG.

Common errors and how to fix them

"This book is encrypted (encryption type 2), which means it is protected by DRM."
The page does not read protected books and does not remove protection. Use a DRM-free copy from the author or publisher.
"This file is a ZIP, not a MOBI or AZW3 book."
A ZIP here is usually an EPUB, or a KFX-ZIP made by another tool; KFX is not supported. A file that is already an EPUB can be opened with the EPUB tools directly.
"Record N points outside the file, which looks truncated."
The download was cut off. Download the book again; the record table at the front names more data than the file holds.

Best practices

  • Open the converted EPUB in two readers before deleting the Kindle original, and compare the contents list and the first and last chapters.
  • Convert from the KF8 or combo file when you have both versions; a MOBI 6-only file loses the stylesheet that KF8 carries.
  • Edit the metadata here instead of in the reader: the title and author in the file are what library apps sort by.

Frequently asked questions

Why does the page refuse some Kindle books?

A book bought from a Kindle store is normally encrypted, and its header says so. The page reads that flag and stops. A book is only converted when its header states that nothing is encrypted.

Does it handle old MOBI files with 'high compression'?

Yes, HUFF/CDIC decoding is implemented. It has not yet met a real high-compression book, so if one fails to convert, report it.

What happens to a picture that cannot be found?

In a MOBI 6 book an image number that points at nothing is dropped from the page. In a KF8 book the broken reference is removed and counted in the lost-links figure.

Why does a MOBI 6 book come out as fewer files than it had page breaks?

Sections shorter than a page between two mbp:pagebreak markers are merged with their neighbours, so the EPUB does not end up with hundreds of tiny files. Contents entries and links still land on the right spot inside the merged file.

Is the output checked against the EPUB standard?

The page checks that every page is well-formed XML and that every link and image points at a file or id that exists. It has not been run through the W3C EPUBCheck validator, so validate it there if a store requires that.