Generate a multi-page PDF from an HTML page using Playwright's page.pdf()

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Launch Chromium (PDF generation is only supported in Chromium); navigate to the target page and wait for all content to load with waitUntil: 'networkidle' or a specific element assertion
  2. Call await page.pdf({ path: 'output.pdf', format: 'A4', printBackground: true }) to render the page with its print CSS media applied and background graphics enabled
  3. Inject @media print CSS or toggle a print class on the page before calling pdf() to control layout, hide navigation, and ensure page breaks occur correctly using CSS page-break properties
  4. Use the margin option to set page margins and the displayHeaderFooter option with headerTemplate/footerTemplate HTML strings to add page numbers or timestamps
  5. For tagged (accessible) PDF output, pass tagged: true; for selective page ranges, pass pageRanges: '1-3, 5'

Known gotchas

Related routes

Generate a PDF from an HTML page using Puppeteer
pptr.dev · 5 steps · unrated
Feed Playwright page.ariaSnapshot() output to an LLM agent loop as a token-efficient page observation
playwright.dev · 6 steps · unrated
Generate a Puppeteer PDF with custom header/footer templates and controlled page breaks
pptr.dev · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans