Generates a single PDF of all SSR documentation listed in
../sidebars.js.
The tool drives a headless Chromium against the standard Docusaurus
production build (../build/), so every page is rendered exactly as it
appears on the live site — including MDX components, partials, Mermaid
diagrams, syntax-highlighted code, tables and images.
- A4 page size, 20mm margins, footer page numbers.
- Cover page (title + build date).
- Clickable table of contents for document titles (H1).
- PDF outline / bookmarks following the sidebar structure.
- Single file at
pdf/out/ssr-docs.pdfby default.
- Node 18+ (matches the repo's
enginesconstraint). - A working
yarn buildin the repo root (the tool can run this for you).
cd pdf
npm installThe first npm install downloads Puppeteer's bundled Chromium (~150 MB).
# Use existing ../build, build if missing
node build-pdf.js
# Force a fresh `yarn build` first
node build-pdf.js --rebuild
# Render only the first 5 docs (useful while iterating)
node build-pdf.js --limit 5
# Custom output location
node build-pdf.js --out out/ssr-docs-2026-05.pdf- Ensures
../build/exists (runsyarn buildif not, or if--rebuildis passed). - Starts a local static server on a random port serving
../build/. - Loads
../sidebars.jsand flattens thedocstree into an ordered list ofpart/chapter/docentries. - For every doc entry, opens
/docs/<docId>in headless Chromium, injects a print stylesheet (hides navbar, sidebar, footer, edit links, pagination), waits for Mermaid SVGs to render, then captures a PDF viapage.pdf(). - Renders a cover HTML and a TOC HTML to PDF. TOC entries point at
placeholder URIs (
https://pdf.local/target/<n>). - Merges cover + TOC + every doc PDF with
pdf-lib, then:- rewrites TOC URI link annotations into in-document GoTo actions targeting the correct absolute page;
- constructs a PDF outline (bookmarks) mirroring the sidebar structure;
- stamps "Page N / M" in the bottom margin of every page after the cover.
- build-pdf.js — orchestrator.
- print.css — print stylesheet injected into each doc page.
- lib/sidebar-walker.js — flattens
sidebars.js. - lib/server.js — local static file server.
- lib/render-pages.js — Puppeteer renderer.
- lib/templates.js — cover + TOC HTML.
- lib/merge.js — PDF merge, link rewriting, outline, page numbers.
- TOC sub-entries (H2 / H3) link to the page in the PDF where the heading is approximately located. The page offset is estimated by measuring the heading's vertical position in the browser against the effective A4 printable height. Top-of-doc links are always exact.
- KB articles (under
../kb/) are intentionally not included; they are organized as a blog, not insidebars.js. - Re-running without
--rebuildreuses an existing../build/. Delete the folder or pass--rebuildto force a fresh build.