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
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
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
Use the margin option to set page margins and the displayHeaderFooter option with headerTemplate/footerTemplate HTML strings to add page numbers or timestamps
For tagged (accessible) PDF output, pass tagged: true; for selective page ranges, pass pageRanges: '1-3, 5'
Known gotchas
page.pdf() only works in Chromium-based browsers; calling it on a Firefox or WebKit page throws an error — ensure your Playwright project config targets Chromium for PDF tasks
Background colors and images are suppressed by default (printBackground: false); many designs become unreadable without backgrounds — always set printBackground: true unless the design is intentionally white-background
External fonts and images loaded via CDN may not render if the page is in a restricted network or if the resources load after the pdf() call; wait for all critical resources to be present before capturing
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp