makesPDF
← Back to How to create a PDF

Headless browsers (Puppeteer, Playwright, Gotenberg)

By Jason Galea · Part of the How to create a PDF benchmark

Takeaway: Puppeteer and Playwright give you full HTML and CSS with working CJK and emoji, but page.pdf() is untagged by default, still fails five PDF/UA-1 rules when tagged, and cannot emit PDF/A.

Sample PDFSizePagesTaggedPDF/UA-1PDF/A-2aZürich / 東京 / 🚀Fig altTable tags
chromium-untagged60 KB2nofail (9r / 3765c)fail (5r / 2090c)✓ ✓ ✓✗✗
chromium-tagged126 KB2yesfail (5r / 35c)fail (4r / 2116c)✓ ✓ ✓✓✓
browser-print114 KB2yesfail (5r / 13c)fail (4r / 2090c)✓ ✓ ✓✓✓

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.

Spinning up headless Chromium and calling page.pdf() is probably the default way backend teams generate PDFs today. Your team already knows HTML and CSS, you can reuse web components and fonts, and the output looks like what you see in Chrome.

The catch isn't visual quality. It's what turns up when you check the file against PDF standards, try to control print pagination, or keep Chromium running cleanly in production.

What we measured

We rendered the shared Quarterly Field Report (reference.html) with Playwright's Chromium 158 in two configurations (browser-print is included in the table above for comparison):

  • chromium-untagged.pdf (60 KB, 2 pages): plain page.pdf({ format: "A4", printBackground: true }), which is what most snippets copy-paste.
  • chromium-tagged.pdf (126 KB, 2 pages): tagged: true, outline: true, plus displayHeaderFooter: true and footerTemplate for "Page n of N".

Two things stand out straight away:

  • The default output has zero tags. chromium-untagged.pdf has no structure tree, no figure alt text, and fails 3,765 PDF/UA-1 checks across 9 rules (2,061 untagged content checks and 1,694 missing natural language checks). Gotenberg also switched Chromium tagging off by default because of file size; you have to pass the pdfua field explicitly to turn it back on.
  • Turning tagged: true on builds a real tree, but still fails PDF/UA-1. chromium-tagged.pdf properly tags H1/H2/H3, both lists, the 36-row table (37 TR, 4 TH, 144 TD), the Figure with /Alt from <img alt>, and the Link. It still fails 5 PDF/UA-1 rules (35 checks):
    1. 7.1-3: page furniture is not marked as an Artifact (30 checks).
    2. 7.1-5: non-standard structure types are not role-mapped (2 checks).
    3. 7.18.5-2: the link annotation is missing /Contents.
    4. 7.18.1-2: an annotation lacks /Contents or /Alt.
    5. 7.1-8: no XMP metadata stream (and no PDF/UA identifier).

Neither mode produces PDF/A. Both failed PDF/A-2a on over 2,000 checks, mostly uncalibrated DeviceRGB without an output intent. If you need PDF/A out of a Chromium pipeline, you have to run a second tool like Ghostscript or LibreOffice afterwards.

One small gotcha we hit during the run: Chromium 158 now honours CSS @page margin boxes (counter(page) / counter(pages)). Because reference.html already defined @page counters and we also turned on Playwright's footerTemplate, chromium-tagged.pdf printed the page number twice. Worth checking if you upgrade an older Puppeteer template.

On the good side, system font fallback handled Zürich, São Paulo, 東京, ✓, 🚀 and ✅ cleanly, and all of them survived text extraction. On a warm local browser, page.pdf() itself took around 30 to 50 ms (excluding browser launch).

Deployment shapes

If you pick headless Chromium, you basically have three ways to run it:

  • Direct Puppeteer or Playwright in your own service: Full control and low marginal cost at steady volume, but you own the browser lifecycle: container size (+200 MB), memory spikes under concurrency, cold starts, font installs, zombie processes, and SSRF hardening whenever user input reaches HTML.
  • Gotenberg (Docker): Packages Chromium and LibreOffice behind an HTTP API so you don't have to write the pooling glue yourself. Remember that Chromium tagging is opt-in, and Gotenberg's PDF/A conversion routes through LibreOffice, where tables with background colours can get rasterised.
  • Hosted browser services (Browserless, Cloudflare Browser Run): Offloads browser ops. For reference, Cloudflare Browser Run lists 10 browser-minutes a day on the free plan and 10 hours a month then $0.09/hour on the paid plan (with concurrency billed separately). Handy if you only print HTML views occasionally; you still inherit Chromium's PDF/UA and PDF/A limits.

Pros and cons

Pros

  • Full HTML, CSS and JavaScript, including web fonts and JS-rendered charts.
  • Reuses existing web views and component libraries.
  • System font fallback handles accents, CJK and colour emoji without manual font registration.

Cons

  • Untagged by default; even with tagged: true, it does not pass veraPDF PDF/UA-1 and cannot output PDF/A.
  • Heavy runtime to operate (memory, cold starts, sandboxing, SSRF surface).
  • Weaker print pagination than dedicated paged-media engines.
  • Output can shift quietly when Chromium updates.

When a headless browser is still the right call

  • You need to capture an existing web page or dashboard that already relies on CSS Grid, Flexbox or client-side JS.
  • PDF/UA-1 and PDF/A-2a compliance are not requirements, or you already have a post-processing pipeline you trust.
  • Everything has to stay inside your own VPC with no external API calls.

If you want real print CSS without operating a browser, look at CSS paged media or Typst. If you already have untagged Chromium PDFs you need to check or remediate, /validate shows the exact failing rules and /enhance lets you test remediation (the first page is free).