# pdf-generation

HTML/markdown to PDF on any machine (WeasyPrint or headless Chrome), page-break rules, merging PDFs, and checking the result.

- **Space:** documents-public (https://github.com/Tech-Realm/space-documents-public/tree/main/pdf-generation)
- **Level:** L1 (as the registry reports it)
- **Keys it needs (names only):** none
- **Tools:** python3
- **Routes:** chrome-local, weasyprint-local, pandoc-local; checks: 3
- **Uses:** new (no recorded use yet)
- **Install:** `logicpacks pack use documents-public/pdf-generation` or MCP `get_pack documents-public/pdf-generation`
- **Files:** CHANGELOG.md, code/merge_pdfs.py, outcome/EVIDENCE.md, outcome/checks.yaml, outcome/fixtures/two-pages.html, outcome/results.json, pack.yaml, spec/SPEC.md, spec/source.md

## Purpose (spec/SPEC.md)

## Goal

Reliable PDF output from HTML: right page size, no blank pages, dark backgrounds printed, verified page count and text.

## Steps

1. Prefer headless Chrome (`../tools/html2pdf.py in.html out.pdf`); WeasyPrint only if it imports cleanly (keeps margin-box footers).
2. Page size via CSS `@page { size: A4 | A4 landscape | 13.333in 7.5in }`, margins in @page not body.
3. One break rule per container (`break-after: page`), `print-color-adjust: exact` for backgrounds.
4. Merge: `python3 code/merge_pdfs.py out.pdf a.pdf b.pdf` (pypdf).
5. 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=8000` lets 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.



---

Canonical URL: https://logicpacks.io/packs/documents-public/pdf-generation

Developed by TechRealm (techrealm.online), the software team. Operated by Al Jash Trading (Establishment), Abu Dhabi, since 1994, the legal entity that hosts and is responsible for the service. Economic licence CN-1030597, Abu Dhabi Registration Authority. Address: Office 5, Bani Yas West 4, Bani Yas, Abu Dhabi, UAE. Website: https://aljashtrading.com. Contact: hello@logicpacks.io, security@logicpacks.io, WhatsApp +1 713 632 2262 (https://wa.me/17136322262).

Machine-readable index: [/llms.txt](/llms.txt). Plain facts: [/about.md](/about.md). Safety: [/safety.md](/safety.md).
