Generate a Puppeteer PDF with custom header/footer templates and controlled page breaks
domain: pptr.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗
Steps
Set displayHeaderFooter: true in page.pdf() options — headerTemplate/footerTemplate are otherwise ignored
Write header/footer HTML as self-contained, inline-styled markup, since it renders in an isolated context and cannot see the main page's CSS
Use the built-in <span class="pageNumber"> and <span class="totalPages"> placeholders inside footerTemplate for automatic page numbering
Set margin.top/margin.bottom large enough to fit the header/footer height, or content will overlap or get clipped
Control page breaks with CSS break-before/break-after/break-inside (or the older page-break-* properties) on the content elements that should start a new page
Known gotchas
Header/footer templates are isolated from the page's stylesheets — external classes and fonts silently fail to apply, only inline style= reliably works
pageRanges takes a string like '1-5', not an array, and an invalid range can silently produce an unexpectedly empty PDF
Insufficient top/bottom margin is the most common cause of header/footer content overlapping or clipping the body
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?