What this thread does
Do first: if the PDF must look exactly like the page in a browser, use a headless Chromium route (Playwright or Puppeteer page.pdf(), or Gotenberg, which wraps Chromium); if the layout is a print document you control, WeasyPrint avoids a browser. Playwright doc Gotenberg README WeasyPrint docs
Short answer
Playwright and Puppeteer both generate a PDF of the page with the print CSS media type by default, and both can be switched to screen media. Playwright doc Puppeteer doc Gotenberg is a Docker-based API that converts HTML, URLs and Markdown to PDF through headless Chromium and also does merging, stamping and PDF/A. Gotenberg README WeasyPrint is a rendering engine for HTML and CSS that exports PDF and is not based on a full browser engine. WeasyPrint docs
Choose / don't choose
| Option | Choose it when | Not for | Source |
|---|---|---|---|
Playwright page.pdf() | You already drive pages with Playwright and want to print one, with print or screen media | Pages whose layout depends on print styles if you force screen media | Playwright doc |
Puppeteer page.pdf() | You already use Puppeteer; it returns the PDF as a Uint8Array | Pages that rely on @media print pagination if you switch to screen media | Puppeteer doc |
| Gotenberg | You want PDF as a service over HTTP, with merge, stamp, sign or PDF/A in the same service, without managing Chromium and fonts yourself | Teams that cannot run Docker; one-off scripts where a library call is enough | Gotenberg README |
| WeasyPrint | You write the HTML and CSS for the PDF yourself (invoices, reports) and want no browser dependency | Copying an existing web page pixel for pixel, since it is not based on a full rendering engine like WebKit or Gecko; setups where Python 3.10+ and Pango cannot be installed | WeasyPrint docs WeasyPrint install |
Not for: avoiding a headless browser by drawing the PDF in code.
Settings that matter
| Setting | Value / behavior | Applies to | Source |
|---|---|---|---|
| Media type | Print by default; page.emulateMedia({ media: 'screen' }) in Playwright, page.emulateMediaType('screen') in Puppeteer | Playwright, Puppeteer | Playwright doc Puppeteer doc |
| Colors | Modified for printing by default; -webkit-print-color-adjust forces exact colors | Playwright, Puppeteer | Playwright doc Puppeteer doc |
| Header and footer templates | Script tags inside templates are not evaluated; page styles are not visible inside them | Playwright | Playwright doc |
| Page size | Named formats such as A4 (8.27in x 11.7in) and Letter, or width and height with px, in, cm, mm | Playwright | Playwright doc |
| Runtime | Python 3.10+ and Pango 1.44+ (the install page read was for WeasyPrint 70.0) | WeasyPrint | WeasyPrint install |
| Runtime | docker run --rm -p 3000:3000 gotenberg/gotenberg:9; POST to /forms/chromium/convert/url | Gotenberg | Gotenberg README |
Order of operations
1. Decide whether the PDF must match the browser view; if yes, pick a Chromium route, otherwise consider WeasyPrint. WeasyPrint docs 2. For Playwright or Puppeteer, load the page, set the media type, then call page.pdf(). Playwright doc Puppeteer doc 3. For Gotenberg, start the container and send the URL or HTML as multipart/form-data. Gotenberg README 4. Open the result and check page breaks and colors before using it in production.
Known failures and fixes
- If backgrounds or colors look washed out in the PDF, use the
-webkit-print-color-adjustCSS property to force exact colors. Playwright doc - If the layout breaks after forcing screen media, restore print media, because screen media disables
@media printstyles. Puppeteer doc - If a header template shows no styling, put the styles inline: page styles are not visible inside templates. Playwright doc
Missing
- This comparison contains no speed, memory or file-size measurements.
- WeasyPrint's documentation quotes the project's early scope as having "no JavaScript"; test script-built pages before choosing it. WeasyPrint background
- Gotenberg's Chromium route options such as wait delay and margins are documented on its Chromium URL conversion page and are not summarized here. Gotenberg URL route
Evidence
Playwright and Puppeteer API pages, the Gotenberg README at a pinned commit and the WeasyPrint documentation. 0 trials in this draft; not tried by WhatWorks.
Checked
2026-12-03; the pages were read as served on that date and the Gotenberg README at the pinned commit.
Started from a post by @Playwright, packaged by the editor. Original post