Packs / documents-public
pdf-generation
HTML/markdown to PDF on any machine (WeasyPrint or headless Chrome), page-break rules, merging PDFs, and checking the result.
Install
logicpacks pack use documents-public/pdf-generationget_pack documents-public/pdf-generationThe second line is the MCP tool call for the LogicPacks connector (Claude Code, Codex, Claude.ai and others). The first run of a pack someone else wrote asks for your yes.
Keys it needs (names only)
None.
Playbooks included
- Spec:
spec/SPEC.md(goal, steps, edge cases, don’ts) - Routes:
chrome-localweasyprint-localpandoc-local - Checks: 3 in
outcome/checks.yaml - Code:
merge_pdfs.py - Tools: python3
Usage, last 8 weeks
New: no recorded use yet.
Purpose (from spec/SPEC.md)
Goal
Reliable PDF output from HTML: right page size, no blank pages, dark backgrounds printed, verified page count and text.
Steps
- Prefer headless Chrome (
../tools/html2pdf.py in.html out.pdf); WeasyPrint only if it imports cleanly (keeps margin-box footers). - Page size via CSS
@page { size: A4 | A4 landscape | 13.333in 7.5in }, margins in @page not body. - One break rule per container (
break-after: page),print-color-adjust: exactfor backgrounds. - Merge:
python3 code/merge_pdfs.py out.pdf a.pdf b.pdf(pypdf). - Verify with
../tools/check_doc.py out.pdf --pages MIN:MAX --expect TEXT(pdftotext or pypdf).
Edge cases
- WeasyPrint missing or broken on the Mac: render.py falls back to headless Chrome (no 'Page X of Y' footer).
- Blank pages in Chrome = the page break is declared twice in CSS; keep one
break-after: page. - Tall screenshots overflow a page: images are capped at 215 mm high in the CSS.
--virtual-time-budget=8000lets web fonts/images load before printing.- Chrome adds headers/footers unless
--no-pdf-header-footer.
Don'ts
- Don't rasterise text into images to 'fix' layout; the PDF must stay searchable.
- Don't hotlink remote fonts/images in client PDFs; vendor them.