Every self-published author I know has, at some point, exported a book, changed one sentence, and then spent an evening working out which of the three files was now out of date.
The EPUB still had the old chapter title. The PDF had the right text and the wrong table of contents. The cover was fine, because the cover never changes, which is exactly why nobody checks it.
The problem isn't the export. It's that the book has three outputs and no single source. Fix the source and the exports follow; fix the exports and you're maintaining three books.
This is a piece about that second option, and why it fails quietly.
Three files, three histories
I've been making books since 2009, first at a science and technology publisher and now at my own imprint. The pattern is the same at every scale.
You finish the manuscript in Word or Scrivener or Google Docs. You export a PDF for print. A layout tool or a designer builds an EPUB. Someone, often you at 11 pm, makes a cover in Canva. Then the copy editor sends back forty small changes.
Now you have a decision. Patch the EPUB in Sigil, and patch the PDF by re-exporting, and hope the cover still matches the title. Or rebuild everything and re-check the table of contents.
Patching is faster the first time. It is also the reason a book ends up with a nav document that lists "Chapter 7: Working With Agents" while the PDF says "Chapter 7: Working With Publishers". Both files are internally consistent. The book is not.
The drift is not random, and it is not sloppiness. Each output has its own editor, its own history, its own idea of the text. Once the three of them disagree, there is no file you can point at and call the book.
Don't fix the output. Rebuild it.
A build you can trust rests on three conditions, and all three have to hold.
One source. The manuscript stays in plain text. Markdown, in my case. The EPUB and the PDF are outputs, never inputs. As soon as you edit the EPUB, it has become a source, and now you have two sources.
One settings file. Title, author, language, trim size, margins, subtitle, ISBN. These are printed into both files and into the cover. If they live in three tools, you will update two of them.
Regenerate from zero. Delete dist/, run one command, get three new files. Not "export again and fix the TOC". A full rebuild, every time.
I wrote a small CLI called BookForge that enforces those conditions for my own projects. Here is the whole settings file for the sample book that ships with it:
title: "The Lean Author's Handbook" subtitle: "From Markdown to Amazon KDP in One Command" author: "Alex Morgan" publisher: "Northwind Press" year: 2026 language: en theme: minimal trim: 6x9 chapters: chapters/*.md output: dist pdf: header: true footer: true toc_depth: 1 margins: {top: 0.75, bottom: 0.75, inner: 0.8, outer: 0.6} gutter: 0.1 cover: kicker: "A FIELD GUIDE FOR INDIE AUTHORS" tagline: "Write once. Publish everywhere." Thirty lines, and a build looks like this:
$ bookforge build The Lean Author's Handbook Alex Morgan · minimal · 6×9in · 9 chapters · 7,422 words ✓ cover.png 120.6 KB 1600×2560px ✓ the-lean-author-s-handbook.epub 237.6 KB EPUB 3 ✓ the-lean-author-s-handbook.pdf 313.9 KB 41 pages · fonts embedded Done in 1.1s. That is the entire idea. Everything else in this post is about the second command, because building is the easy half.
What actually gets a KDP file rejected
Upload errors are mostly packaging errors, and packaging is invisible in the tools that produce it. These are the ones I have hit most often, with the check I now run for each.
1. The mimetype entry. It has to be the first entry in the ZIP and stored without compression. A normal zip call compresses it, and you get "invalid EPUB" from a file that opens fine in Calibre. Check it with:
unzip -l book.epub | head -3 The first line must be mimetype, and the compression column must say Stored. If you generate the EPUB yourself, write that entry first and pass ZIP_STORED for it:
import zipfile with zipfile.ZipFile("book.epub", "w") as zf: info = zipfile.ZipInfo("mimetype", date_time=(1980, 1, 1, 0, 0, 0)) zf.writestr(info, "application/epub+zip", compress_type=zipfile.ZIP_STORED) # everything else after this, compressed normally 2. Navigation. You need a nav document, and older Kindles want an NCX fallback. The failure mode I see most is a table of contents generated from page numbers rather than links. It looks right in a browser preview and dies on a device. Resolve every href in the nav against the files in the ZIP, not against the rendered page.
3. Cover size. 1,600 × 2,560 px is the recommendation because of the 1:1.6 aspect ratio stores display. A cover saved as a single flat colour, or at 1,601 px on one side, gets flagged or looks wrong in the thumbnail. Check width, height, and that the image is not one solid colour.
4. Embedded fonts. If the PDF references a font that is not in the file, the printer substitutes it and your line breaks move. pdffonts gives you the answer per font:
pdffonts interior.pdf Every row in the emb column should read yes.
5. Trim size. The interior PDF has to match the trim you selected on the store side. A 6×9 PDF uploaded into a 5.5×8.5 paperback setting shows up as a margin error, and the message does not tell you that's what happened.
pdfinfo interior.pdf | grep "Page size" 6. Blank pages. They come from page breaks around chapter openers, and reviewers notice them even when readers skip them. Walk the PDF, pull the text of each page, and list the ones with nothing on them:
from pypdf import PdfReader for i, page in enumerate(PdfReader("interior.pdf").pages, start=1): if not (page.extract_text() or "").strip(): print("blank:", i) 7. Dead internal links. Preview catches a broken TOC link that a validator forgot. Same walk as item 2, applied to every content file, not just the nav.
One more that is not a rejection but a bookkeeping problem: the identifier. If your build generates a fresh random UUID every time, the store treats the rebuild as a different book, and you lose the link between old and new uploads. Keep the identifier stable once you have published.
Write the validator before the page
The habit that saved me the most evenings is not a build tool. It is checking the output automatically, before it goes anywhere near a store.
Rule: the check exits 0 or it names the file and the page that is wrong. No eyeballing, no "looks fine in the previewer". Then the same command runs in a shell one-liner or a pre-commit hook:
bookforge validate --strict || echo "not uploadable" On the sample book, it prints this:
EPUB ✓ mimetype — First entry, stored, exact value ✓ Metadata — Title, author, language and identifier present ✓ Cover image — 1600×2560px, PNG, 120.6 KB ✓ Navigation — 68 entries, all resolve ✓ Spine — 13 documents in reading order ✓ Empty pages — Every content document has text ✓ Links and images — 2 embedded images, no broken internal links PDF ✓ Pages — 41 pages ✓ Trim size — 6.00×9.00in (expected 6×9in) ✓ Blank pages — No blank pages ✓ Embedded fonts — 6 embedded font faces used by the text ✓ Bookmarks — 9 outline entries 25 passed, 0 warnings, 0 errors Exit codes are 0 for clear, 1 for errors (or warnings under --strict), 2 when the project itself can't be read. That last one matters in automation: a broken book.yaml should not look like a clean build.
A validator you wrote yourself is worth more than a checklist, because a checklist is a document and a validator is a command. The checklist gets skipped the week you are tired. The command runs in CI.
The honest part
You do not need my tool to do any of this, and I would rather say that than have someone buy a CLI because a blog post implied it was magic.
The pipeline is: parse Markdown into a document model, write EPUB 3 by hand (zip, OPF, nav, NCX, XHTML, CSS), lay out the print interior with ReportLab, generate a cover with Pillow, then validate all three. Half a day gets you a working version if you have done it before. The parts that take longer than you expect are the ones you cannot see: making the table of contents converge (ReportLab's multiBuild lays out the contents page repeatedly until the page numbers stop moving), keeping the mimetype entry correct through every refactor, and getting hyphenation and justification to look like a book rather than a web page.
If you would rather skip that, BookForge is $39 once, source included, with the 41-page sample book in the package so you can inspect the output before buying. It runs offline on Python 3.10+, there is no account and no subscription, and 42 tests cover the parser, all three trim sizes, the EPUB structure and the PDF metadata.
- Gumroad: https://yklee.gumroad.com/l/bookforge-cli?utm_source=devto
- Polar: https://buy.polar.sh/polar_cl_2bN6Ctmd4AWCpDYbfjyLGSUvT3iaxW2XWWxH70HVKDU?utm_source=devto
What it does not do, in v1.0: footnotes, math typesetting, fixed-layout children's books, or uploading for you. It also will not tell you whether your description sells the book. That one is still yours.
If you are getting a rejection I have not listed here, put the error text in the comments. I have probably hit it, and if I have not, I would like to know what it says.