azw3-to-pdf
                     _____    __                     ______
  ____ ______      _|__  /   / /_____     ____  ____/ / __/
 / __ '/_  / | /| / //_ <   / __/ __ \   / __ \/ __  / /_
/ /_/ / / /| |/ |/ /__/ /  / /_/ /_/ /  / /_/ / /_/ / __/
\__,_/ /___/__/|__/____/   \__/\____/  / .___/\__,_/_/
                                      /_/

Kindle books, laid out as PDFs.

One Go binary reads .azw3, .azw, .mobi and .prc and lays them out as real PDFs: selectable text, outline bookmarks from the book's own headings, the cover, the illustrations, the typography its stylesheet asked for. No Calibre. No Python. No Ghostscript. Nothing else to install.

go install github.com/jparkerweb/azw3-to-pdf/cmd/azw3-to-pdf@latest
Download a build

4 input formats 8 layout presets 12 page sizes 0 runtime dependencies MIT licensed

Kindle book formats being converted into PDF documents

Everything is in the binary

A converter, not a wrapper around one.

Most Kindle-to-PDF tools shell out to Calibre and hope it is installed. This one carries the whole pipeline: the Palm container reader, the MOBI/KF8 parser, both decompressors, the markup and CSS layout engine and the PDF writer. Five stages, one file, nothing to set up before the first conversion.

input file bytes .azw3, .azw, .mobi or .prc
stage 1 ebook Palm container, MOBI/KF8 headers, PalmDOC and HUFF/CDIC decompression, resources
stage 2 htmldoc The book's markup and its own stylesheet, flattened into layout blocks
stage 3 pdfout Wrapping, justification, fonts, illustrations, bookmarks, page numbers
output a real PDF Selectable text and a working outline

A file browser in the terminal

Run it with no arguments and pick a book. Multi-select with space, convert the batch with b, type a path with tab, switch drives with d.

Batch conversion

Point it at a folder, add --recursive, and run several conversions at once with --jobs 4. Existing files can be overwritten, renamed or skipped.

Presets first, knobs after

Eight named starting points, from ereader to manuscript, plus a suggestion based on how long and how illustrated the book is. Every setting can be overridden.

The book's own typography

Kindle books style their headings with CSS classes, not heading tags. The stylesheet is read, so chapter titles look like chapter titles and hanging indents survive the trip.

PDFs, not pictures of pages

Selectable, searchable text. An outline built from the headings, page numbers, an optional running header, the cover art, a generated title page and document metadata.

Fonts that cannot fail

A system serif, sans or mono face where one exists, or your own .ttf. If nothing suitable is installed, typefaces embedded in the binary take over.


The interface

Answer four questions, get a PDF.

Pick a book, look at what is inside it, choose how the pages should read, watch it convert. Two colour themes, switchable mid-run with ctrl+t and remembered next time. Or skip the whole thing with --no-tui and pass flags.

azw3-to-pdfpresets
How should the pages look?

  E-reader
    A5 (148 x 210 mm) · serif 11.0pt · 14mm margins · justified

  Paperback       suggested
    Trade paperback (6 x 9 in) · serif 11.5pt · 18mm margins · justified

> Print
    US Letter (8.5 x 11 in) · serif 11.5pt · 22mm margins · justified
    US Letter with generous margins, sized for printing and annotating.

  Compact
    A5 (148 x 210 mm) · serif 9.5pt · 9mm margins · justified

  Large print
    A4 (210 x 297 mm) · sans 16.0pt · 18mm margins · ragged right

enter use this layout    r jump to the suggestion
l layout  ·  p presets  ·  ctrl+t theme  ·  ? shortcuts  ·  ctrl+c quit

Convert one book from the shell

azw3-to-pdf book.azw3 --no-tui

A whole folder, four at a time

azw3-to-pdf ~/Books --recursive --no-tui \
  --output-dir ~/PDFs --jobs 4

Look inside a book without converting it

azw3-to-pdf probe book.azw3 --verbose

A preset, then your own measurements

azw3-to-pdf book.azw3 --no-tui \
  --preset paperback --page-size 120x160mm \
  --font-size 12 --line-spacing 1.5

Presets

Eight ways to read the same book.

A preset sets the page size, margins, typeface, text size, leading and justification in one go. azw3-to-pdf presets prints the list; any part of it can be overridden on the command line or in config.yaml.

KeyPresetLayout
ereaderE-readerthe defaultA5, 11 pt serif, 14 mm margins, justified. The best all-round reading layout.
paperbackPaperbackTrade 6 × 9 in with book margins and a running header. Looks like a printed novel.
printPrintUS Letter with generous margins, sized for printing and annotating.
a4A4A4 with standard margins, for everywhere that is not the US.
compactCompactSmall type and thin margins. Roughly a third fewer pages.
large-printLarge printA4, 16 pt sans and open leading for comfortable reading.
phonePhoneA narrow page that fills a phone screen without pinch-zooming.
manuscriptManuscriptDouble-spaced Letter pages for editing and mark-up.

What it understands

The awkward parts, handled.

A Kindle file is a Palm database from the 1990s wrapped around HTML, compressed with a Huffman scheme that has to be decoded in 64-bit arithmetic or it yields plausible-looking nonsense. All of that is dealt with before the layout engine sees a word.

ContainersPalm database: .azw3, .azw, .mobi, .prc
FormatsKF8 (MOBI 8) and MOBI 6, including dual-format files where both halves are present
CompressionNone, PalmDOC (LZ77) and HUFF/CDIC
TextUTF-8 and Windows-1252
ImagesJPEG, PNG, GIF and BMP, plus the cover art
StylingThe book's own stylesheet: alignment, relative font sizes, margins, hanging indents and page breaks
PlatformsWindows, macOS and Linux, on amd64 and arm64

DRM is not removed

A book bought from the Kindle store and never de-authorised is encrypted. It says so plainly rather than producing a PDF of noise. Convert books you own, in an unencrypted form.

.kfx is not supported

The newest Kindle format is a different container altogether, and this reads the Palm database family. If your file is .kfx, this is not the tool for it.


Point it at a book.

Go 1.25, or a prebuilt binary for your platform. Nothing else.

go install github.com/jparkerweb/azw3-to-pdf/cmd/azw3-to-pdf@latest
View on GitHub