Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PDF export

generate:pdf <export-directory> --output-directory <dir> [--clean] [--browser <path>] [--pdf-jobs <n>]
generate:site <export-directory> --output-directory <dir> [--clean] --with-pdf [--browser <path>] [--pdf-jobs <n>]

Each book prints to one A4 PDF that looks like its site page: same stylesheet, same fonts, same parchment content block. You get the PDFs two ways:

CommandOutput
generate:pdf<dir>/<language-slug>/<book>.pdf only, no HTML
generate:site --with-pdfThe site, plus <book>.pdf next to each <book>.html, linked from a PDF link at the end of the line under the book’s title

A PDF has the same file name as the book’s page, with .pdf in place of .html (BookFileNaming.GetPdfFileName), so both commands name a book’s PDF the same way.

Requirements

Printing needs Firefox. The generator looks for firefox, then firefox-esr, on PATH, or uses --browser <path>. The flake’s dev shell provides firefox. Without it, the command logs an [ERROR] and writes nothing: generate:site --with-pdf doesn’t fall back to a site without PDFs.

What a PDF contains

The printable page (BookPageWriter.RenderPrintable) has its own template, book_pdf.sbn, and its own stylesheet, Assets/pdf.css, which imports the site’s style.css for the book typography. It holds three parts:

  1. The cover. The title alone, centered on the first sheet, on the parchment and in the book’s default face, the same as the content. A language without a default face falls back to Georgia.
  2. The content, full page. The book’s text alone, without title, heading or site layout, on parchment that covers the whole A4 sheet. The page has no margin (@page { margin: 0 }): the parchment is the root element’s background, fixed so every page gets the whole gradient, and the text margin is the .content block’s padding, repeated on every page by box-decoration-break: clone. A placeholder book’s referenced artwork prints open below its note.
  3. The metadata, on a page of its own. The title, then one plain label: value line per field (the same fields as the site’s Metadata tab, see Book page contents), then the number of locations, leveled lists and scripts. No location details, no “set by X” sources, no images, in a system font on a white page. The site’s copyright footer, without its link to the about page, sits at the bottom of this page: the page is a flex column of at least one A4 sheet, and the footer is part of it rather than of the page shell, so it never spills onto a parchment page of its own.

Nothing in pdf.css applies to the site, and printing a site page from your browser uses the browser’s defaults.

Limitations:

  • No page numbers or running footer. WebDriver BiDi’s print command has no header or footer option, Firefox’s own footer preferences don’t apply to it, and Firefox doesn’t support @page margin boxes (@bottom-right { content: counter(page) }).
  • The PDF is not tagged and has no outline.
  • With Firefox, a page’s background stops at the @page margin, which is why the text margin is a padding rather than a page margin.

How it works

TypeRole
Rendering/Pdf/FirefoxProcessStarts headless Firefox with a temporary profile and reads its WebDriver BiDi endpoint from stderr
Rendering/Pdf/BidiConnectionWebDriver BiDi client over one WebSocket
Rendering/Pdf/PdfPrinterA pool of --pdf-jobs tabs; navigates, waits for images and fonts, prints
Rendering/Pdf/BookPdfWriterRenders the printable page to a temporary HTML file, prints it (one retry on failure), deletes the file
LanguagePdfGeneratorOne language for generate:pdf
LanguageSiteGeneratorOne language for generate:site, calling BookPdfWriter before writing each page

Both commands share ExportLanguage.Discover (the language folders and their output names), BookBatch.ForEachAsync (reading a language’s books concurrently and naming them) and BookPdfWriter. generate:site never calls generate:pdf.

The printable page is a temporary file, so its asset URLs are absolute file:// URLs:

Assetgenerate:pdf reads it fromgenerate:site --with-pdf reads it from
Textures<export>/textures/<site>/textures/
Fonts<export>/localized/<language>/fonts/<site>/<language-slug>/fonts/
Stylesheeta copy in the temporary directorya copy in the temporary directory

TextureAssets.WithUrlPrefix and FontAssets.Build(fonts, urlPrefix) give these URLs; the site page keeps its relative ones.

The communication with Firefox is written with ClientWebSocket and Utf8JsonWriter/ JsonDocument, without a WebDriver package, so it stays Native AOT safe.

Firefox profile

Each run uses a fresh temporary profile. Its user.js sets security.fileuri.strict_origin_policy to false: by default Firefox only lets a file:// page load fonts from its own directory, and the printable page loads them from the export or the site. The other preferences there only skip first-run prompts, telemetry and updates.

Lazy images

The printable page drops the loading="lazy" attribute the site’s images carry: with it, the English PDFs don’t finish within 20 minutes.

Placeholder books

A placeholder book’s note prints in the game’s own Arial, one of the web fonts every language exports, rather than the site’s system font stack. Firefox prints a page set only in system fonts many times slower, and the cost grows with the number of such pages printing at once: 8 copies of a treasure map printed together take 46 s in system fonts and 5 s in Arial, and enough of them printing at once hit the 120 s print timeout. The metadata page stays in system fonts, since switching it doesn’t change the time.

Firefox prints an <a href> as a clickable link annotation, with its default profile. It drops the annotation when the link sits inside an element with opacity below 1: the site footer’s muted look comes from opacity, so pdf.css resets it on the metadata page and greys the text with color instead. Check a PDF’s links with qpdf --qdf --object-streams=disable in.pdf out.pdf, then search out.pdf for /Subtype /Link.

Verbose output

With --verbose, each book logs its print time split into tab wait, load, images and fonts, and print, and the run ends with the average per phase. The tab wait is how long a book queued for a free tab. When it dominates, the tabs are all busy and --pdf-jobs limits the run. When the print phase dominates, Firefox is the bottleneck.

Performance

Measured with generate:site --with-pdf on the full export (9 languages × 1042 books), Native AOT binary, 16-core machine, Firefox 156, --pdf-jobs 64:

MeasureValue
Whole run, site and 9378 PDFs11 min 13 s
One language, generate:pdfabout 70 s
PDFs, all languages1.35 GB, median 47 KB per book
Site size with PDFs1.8 GB

Printing is latency-bound, not CPU-bound: the process uses about 7 minutes of CPU over the 11-minute run, and Firefox sits idle for part of each print. Many tabs in flight hide that latency, which is why --pdf-jobs defaults to four tabs per processor. Throughput stops growing past about 64 tabs on this machine, and running several Firefox processes instead of one tab pool doesn’t raise it.

The largest PDFs are the books with images: a texture is embedded at its full resolution.