Puppeteer page.pdf() viewport and pagination limits when generating multi-page documents
0 reputation · 18 Dec 2020, 16:24 UTC
I'm using Puppeteer to generate PDFs from rendered HTML pages via page.pdf(), and I need to understand the documented limits of this API before committing to it for a reporting feature.
My understanding is that page.pdf() captures the page as Chrome's print pipeline sees it, with options like format, margin, printBackground, and scale. What is unclear to me is how much control I actually have over pagination. Content that flows beyond a single page seems to break according to Chrome's print layout rather than anything I configure directly, and CSS like page-break-before appears to be the only lever.
I'm also unsure how viewport size and headless rendering interact with the output: whether the viewport at goto() time affects which content is laid out for the PDF, and whether font rendering differences between headless Chrome and a visible browser can shift line breaks and therefore page breaks.
Specific questions:
- Does
page.pdf()always capture the full document height, or can content outside the current viewport be omitted? - Is CSS print pagination (
@page, break properties) the only supported way to control page breaks? - Should the viewport be fixed explicitly before calling
page.pdf()to get deterministic output?