CSS paged media (WeasyPrint, Prince / DocRaptor, Paged.js)
By Jason Galea · Part of the How to create a PDF benchmark
Takeaway: CSS paged-media engines fix Chromium's weak print layout. WeasyPrint 70.0 passed PDF/UA-1 cleanly with one flag, though it can only emit one PDF standard per run and needs native Pango/Cairo deps.
| Sample PDF | Size | Pages | Tagged | PDF/UA-1 | PDF/A-2a | Zürich / 東京 / 🚀 | Fig alt | Table tags |
|---|---|---|---|---|---|---|---|---|
| weasyprint-default | 91 KB | 3 | no | fail (9r / 559c) | fail (8r / 934c) | ✓ ✓ ✓ | ✗ | ✗ |
| weasyprint-pdfua1 | 98 KB | 3 | yes | PASS | fail (8r / 934c) | ✓ ✓ ✓ | ✓ | ✓ |
| weasyprint-pdfa2a | 101 KB | 3 | yes | fail (1r / 1c) | fail (1r / 5c) | ✓ ✓ ✓ | ✓ | ✓ |
| weasyprint-pdfua2 | 99 KB | 3 | yes | fail (2r / 2c) | fail (9r / 939c) | ✓ ✓ ✓ | ✓ | ✓ |
| pagedjs | 113 KB | 2 | yes | fail (5r / 13c) | fail (4r / 2042c) | ✓ ✓ ✓ | ✓ | ✓ |
Checked with veraPDF 1.28.2 (r = failed rules, c = failed checks). Click any sample name to download the PDF, or test your own output in /validate (free, no sign-in) and inspect structure trees in /tags.
If you like authoring documents in HTML and CSS but keep fighting Chromium over running headers, page counters, footnotes and awkward page breaks, CSS paged-media engines exist specifically for that job.
They implement the W3C CSS Paged Media specifications (@page margin boxes, named pages, string-set, target counters, better break control) rather than treating printing as an afterthought on top of a screen renderer.
What we measured
We ran the shared Quarterly Field Report (reference.html) through WeasyPrint 70.0 in four modes and through Paged.js 0.4.3 (running on top of Chromium 158):
WeasyPrint 70.0
weasyprint-default.pdf(90 KB, 3 pages): untagged by default. Fails PDF/UA-1 on 9 rules (559 checks) and PDF/A-2a on 8 rules (934 checks).weasyprint-pdfua1.pdf(98 KB, 3 pages,--pdf-variant pdf/ua-1): passed PDF/UA-1 with zero failures and no workarounds. ProperH1/H2/H3, lists withLbl/LBody,Table/THead/TBody/TR/TH/TD,Figure/AltandLink. Still fails PDF/A-2a (8 rules / 934 checks, mostlyDeviceRGBand imageInterpolate).weasyprint-pdfa2a.pdf(101 KB, 3 pages,--pdf-variant pdf/a-2a): tagged, missed PDF/UA-1 by 1 check and missed PDF/A-2a by 1 rule (5 checks).weasyprint-pdfua2.pdf(98 KB, 3 pages,--pdf-variant pdf/ua-2): failed PDF/UA-2 on just 2 rules (6 checks:ListNumberingonLbland structure destinations). That is closer to UA-2 than most tools in the set.
Two practical quirks showed up in the WeasyPrint run:
--pdf-variantonly accepts one variant per run, so PDF/UA-1 and PDF/A-2a are currently an either/or choice in WeasyPrint.- WeasyPrint logs a warning and falls back to
fontToolswhenharfbuzz-subsetis missing from the system environment. On the plus side, system font fallback handledZürich,São Paulo,東京,✓,🚀and✅cleanly, and@pagecounters worked as expected.
Paged.js 0.4.3
Paged.js is a JavaScript polyfill that paginates HTML inside Chromium. Because it uses Chromium to print, pagedjs.pdf (112 KB, 2 pages) got nice paged-media layout (fitting on 2 pages where WeasyPrint took 3) and inherited Chromium's exact tag tree and exact 5 PDF/UA-1 failures (13 checks) plus zero PDF/A support. It also gets noticeably slower as document length grows.
Prince and DocRaptor
Prince is the long-standing commercial engine in this category, and DocRaptor is hosted Prince as an API. Both advertise strong print CSS and PDF/UA support. We have not run our reference report through a trial key yet, so they are not in the scorecard above. On cost, aggregator pricing for DocRaptor starts around $15/month for 125 documents, and a self-hosted Prince server licence is quoted from roughly $2,500/year (check their current pricing pages before budgeting).
Pros and cons
Pros
- Best print CSS support available: running headers and footers, footnotes, cross-references and sane page-break controls.
- WeasyPrint is free (BSD-3-Clause) and passed veraPDF PDF/UA-1 cleanly with one flag.
- Familiar HTML and CSS authoring for web teams, with working CJK and emoji fallback.
Cons
- WeasyPrint runs no JavaScript and depends on native system libraries (Python, Pango, Cairo, HarfBuzz, fontconfig), which means Docker/CI maintenance and occasional layout drift across base-image upgrades.
- WeasyPrint cannot emit PDF/UA-1 and PDF/A-2a in the same pass.
- Prince is expensive for smaller teams; Paged.js still requires headless Chromium and slows down on large documents.
When CSS paged media is the right call
- You already have a Python backend (or can run a small Python worker), want real print CSS without shipping Chromium, and need PDF/UA-1 (not combined PDF/UA-1 + PDF/A-2a).
- You are generating books, long reports or legal/financial documents with footnotes, running chapter titles and strict CSS
@pagerules, and you have the budget for Prince or DocRaptor.
If you don't need HTML/CSS specifically and want a single fast binary that passes both PDF/UA-1 and PDF/A-2a, take a look at Typst. If you want to skip native deps altogether with a hosted endpoint, see makesPDF or our DocRaptor comparison.