build
Parse MDX files, validate them, compose HTML, and render to PDF and/or EPUB.
pretty-pdf build [flags]
| Flag |
Default |
Description |
--format |
"pdf" |
Output formats: pdf, epub, or pdf,epub |
--out |
"out.pdf" |
Output path (extension determines single format; base name for multi-format) |
--title |
"" |
Book title |
--subtitle |
"" |
Book subtitle |
--author |
"" |
Book author |
--theme |
"default" |
Theme name (builtin, custom, or a .theme.yml/.css path) — see Themes |
--css |
"" |
Custom CSS file path (overrides the theme entirely) |
--template |
"" |
Custom HTML template file path (overrides the theme's HTML) |
--cover-image |
"" |
Custom cover image (.png/.jpg/.jpeg/.svg/.webp); the cover page is sized to the image's own dimensions, replacing the text cover |
--timeout |
"" |
Render timeout (e.g. 30s, 1m) |
--language |
"en" |
EPUB language (BCP-47 tag, e.g. en, es) |
--json |
false |
Output as JSON |
--no-cover |
false |
Omit the cover page |
--no-toc |
false |
Omit the table of contents |
--no-page-numbers |
false |
Omit page numbers |
--no-header |
false |
Omit the running page header |
--no-outline |
false |
Skip PDF bookmarks/outline — faster on very large documents |
--no-tagged-pdf |
false |
Skip PDF accessibility tagging (PDF/UA) — faster on very large documents |
--color-primary |
"" |
Theme override: primary color (e.g. #1a56db) |
--color-accent |
"" |
Theme override: accent color |
--color-text |
"" |
Theme override: body text color |
--color-muted |
"" |
Theme override: muted/caption text color |
--color-bg |
"" |
Theme override: page background color |
--font-heading |
"" |
Theme override: heading font family |
--font-body |
"" |
Theme override: body font family |
--font-code |
"" |
Theme override: code font family |
--density |
"" |
Spacing density: compact, normal, or relaxed |
--allow-network-fonts |
false |
Allow fetching Google Fonts declared by the theme (enables network access) |
Build Pipeline
The build command runs through these stages per format:
- Parse — Read and parse all MDX files in the source directory
- Validate — Check frontmatter, duplicate IDs, heading depth, content warnings
- PDF compose — Assemble HTML with TOC, cover page, and embedded CSS/template (PDF only)
- PDF render — Generate PDF via headless Chrome, then run an automatic quality audit (PDF only)
- EPUB write — Package chapters directly into EPUB 3, no Chrome needed (EPUB only)
Chrome is only required when pdf is in the format list. An epub-only build (--format epub) skips Chrome detection entirely.
PDF Quality Audit
Right after rendering, build runs a best-effort audit of the composed document and reports anything worth a second look — it's advisory for DOM/layout findings and only reports at error severity for output that's actually corrupt. The final summary's Warnings count reflects this (and --json's warnings array lists them in full). Checks:
| Check |
Flags |
overflow-x |
Content wider than its box (long code lines, wide tables/images) that print will clip instead of wrap |
overflow-y |
Content taller than a fixed-height box, so it clips when printed |
broken-image |
An <img> that never resolved to real pixels |
image-low-res |
An image displayed at more than ~2x its intrinsic size, so it will look pixelated on paper |
empty-content |
The document has almost no visible text — usually a sign composition silently produced nothing |
low-contrast |
Text whose contrast ratio fails WCAG 2.2 (4.5:1 normal, 3:1 large text) against its effective background |
heading-clip-risk |
A heading that forces a page break without enough top margin to clear the print engine's header/margin strip, so its top would render clipped |
broken-anchor |
An <a href="#fragment"> with no matching element — dead in-document links break TOC and PDF bookmarks |
duplicate-id |
The same id attribute used twice, which breaks anchors, the TOC, and PDF bookmarks |
toc-mismatch |
The TOC links to an id that doesn't exist, or a body section heading has no TOC entry |
font-load-fail |
A font family the page requests could not be loaded (missing local font, or a Google Font blocked by the default network lockdown) and will silently fall back |
page-break-inside-risk |
A table/code block without page-break-inside: avoid, so print can slice it mid-row |
line-break-risk |
A block with orphans/widows below 2, so a single line can be stranded at the top/bottom of a page |
page-count |
The generated PDF has no detectable pages — the output file may be empty or corrupt |
pdf-empty |
The generated PDF is zero bytes — the output file is empty |
pdf-eof-missing |
The generated PDF is missing its %%EOF marker — the output may be truncated or corrupt |
unused-component |
A component registered via WithComponent() was never used in any document — check the tag spelling |
The audit reads the composed HTML before it's handed to the print engine, so it can't see two things that live purely inside Chrome's own print pipeline: the fixed ~0.2in header/footer inset and the actual page-break slicing (both covered by base.css's own layout rules instead — see the CHANGELOG for the bugs those rules exist to prevent).
Pre-flight Checks
Before the pipeline starts, build verifies (per selected formats):
- Chrome/Chromium is available (only when
pdf is in the format list)
- Source directory exists
- At least one
.md/.mdx/.txt file is present
- Each output path's directory is writable
- Custom CSS file exists (if specified)
- Custom template file exists (if specified)
- Custom cover image exists and is a supported format (
.png/.jpg/.jpeg/.svg/.webp, if specified)
check
Parse and validate all MDX files without building a PDF. Previously named validate.
pretty-pdf check [flags]
| Flag |
Default |
Description |
--strict |
false |
Treat content warnings as errors |
epub
Parse MDX files, validate them, and write a single EPUB 3 file — no
Chrome/Chromium involved, unlike build. Each MDX document becomes its own
chapter, in the same order as the PDF's table of contents.
pretty-pdf epub [flags]
| Flag |
Default |
Description |
--out |
"out.epub" |
Output EPUB path |
--title |
"" |
Book title |
--subtitle |
"" |
Book subtitle (used as the EPUB's dc:description) |
--author |
"" |
Book author |
--theme |
"default" |
Theme name (theme CSS is converted to reflowable EPUB form) |
--css |
"" |
Custom CSS file path (overrides theme entirely) |
--cover-image |
"" |
Custom cover image (.png/.jpg/.jpeg/.svg/.webp), full-bleed as the first page |
--language |
"en" |
Book language (BCP-47 tag, e.g. en, es) |
--color-primary |
"" |
Theme override: primary color |
--color-accent |
"" |
Theme override: accent color |
--color-text |
"" |
Theme override: body text color |
--color-muted |
"" |
Theme override: muted/caption color |
--color-bg |
"" |
Theme override: page background color |
--font-heading |
"" |
Theme override: heading font family |
--font-body |
"" |
Theme override: body font family |
--font-code |
"" |
Theme override: code font family |
--density |
"" |
Spacing density: compact, normal, or relaxed |
--allow-network-fonts |
false |
Allow fetching Google Fonts declared by the theme |
Reuses --source/--config like every other command, and render.cover_image
from go-pretty-pdf.yml if --cover-image isn't passed — the same cover
image works for both build and epub. Unlike PDF output — which uses
@page rules and print-oriented layout — EPUB uses the same theme system
through ResolveForEPUB, which produces a reflowable stylesheet (relative
units, no print-only rules, no cover/TOC/page-number sections) that works
across e-reader devices.
theme
List, inspect, and manage themes.
pretty-pdf theme list
pretty-pdf theme show <name>
pretty-pdf theme new <name> [flags]
pretty-pdf theme add <path> [flags]
theme list
Prints every builtin theme (name + description) followed by any custom
themes discovered in ./themes/ (project) and the global themes directory
(~/.config/pretty-pdf/themes on Linux, via os.UserConfigDir()).
theme show <name>
Resolves a theme (builtin, custom, or a .theme.yml/.css path) with no
customization and prints its final, fully-assembled CSS to stdout — useful
to inspect a theme or pipe it somewhere (pretty-pdf theme show dark > dark.css).
theme new <name>
Scaffolds a starter <name>.theme.yml you can hand-edit.
| Flag |
Default |
Description |
--from |
"default" |
Builtin theme to base the scaffold on |
--global |
false |
Write to the global themes directory instead of ./themes |
Refuses to overwrite an existing file.
theme add <path>
Imports an existing .theme.yml or raw .css file as a managed custom
theme (a loose .css file is wrapped into a minimal .theme.yml with
extends: default and the file's content as its css: block).
| Flag |
Default |
Description |
--as |
"" |
Name to register the imported theme under (default: derived from the file name) |
--global |
false |
Copy to the global themes directory instead of ./themes |
init
Scaffold a new book project with sample MDX files and configuration.
pretty-pdf init [directory] [flags]
Interactive mode (default): runs a terminal form asking for title, author, theme, source directory.
| Flag |
Default |
Description |
--bare |
false |
Non-interactive init with flags |
--title |
"My Book" |
Book title (for --bare) |
--author |
"go-pretty-pdf" |
Book author (for --bare) |
--theme |
"default" |
Book theme (for --bare) |
--json |
false |
Output as JSON |
serve
Parse MDX files, compose HTML, and serve with live reload on file changes. No Chrome required.
pretty-pdf serve [flags]
| Flag |
Default |
Description |
--port |
8080 |
HTTP server port |
Uses Server-Sent Events for live reload. Watches .md, .mdx, .txt, .yaml, and .yml files for changes.
watch
Watch the source directory for changes and rebuild the PDF on every file change.
pretty-pdf watch [flags]
Debounces changes by 300ms. Watches .md, .mdx, .txt, .yaml, and .yml files. Prints a build/error summary on Ctrl+C.
version
Print the version number.
pretty-pdf version
completion
Generate shell completion scripts.
pretty-pdf completion [bash|zsh|fish|powershell]
| Shell |
Install command |
| bash |
pretty-pdf completion bash > /etc/bash_completion.d/pretty-pdf |
| zsh |
pretty-pdf completion zsh > "${fpath[1]}/_pretty-pdf" |
| fish |
pretty-pdf completion fish > ~/.config/fish/completions/pretty-pdf.fish |
| powershell |
pretty-pdf completion powershell > _pretty-pdf.ps1 then . .\_pretty-pdf.ps1 |