Skip to Content
PDF Generation

PDF Generation from Firefox via CDP

Foxbridge implements Page.printToPDF with IO stream support for Puppeteer v24+.

Usage

const pdf = await page.pdf({ format: 'A4', printBackground: true, landscape: false, margin: { top: '1cm', bottom: '1cm' }, }); fs.writeFileSync('page.pdf', pdf);

Supported Parameters

ParameterTypeDefaultDescription
landscapebooleanfalseLandscape orientation
displayHeaderFooterbooleanfalseShow header/footer
printBackgroundbooleanfalseInclude background graphics
scalenumber1.0Page scale factor
paperWidthnumber8.5Paper width in inches
paperHeightnumber11Paper height in inches
marginTopnumber0Top margin in inches
marginBottomnumber0Bottom margin in inches
marginLeftnumber0Left margin in inches
marginRightnumber0Right margin in inches
headerTemplatestring""HTML for header
footerTemplatestring""HTML for footer
preferCSSPageSizebooleanfalseUse CSS @page size
pageRangesstring""Page ranges (e.g., "1-3")

All parameters are forwarded directly to Juggler’s Page.printToPDF.

IO Stream Protocol

Puppeteer v24+ uses the IO domain to read PDF data via streaming instead of reading the base64 data field directly. Foxbridge supports both approaches:

  1. Page.printToPDF returns {data: "...", stream: "pdf-stream-123"}
  2. Puppeteer calls IO.read({handle: "pdf-stream-123"})
  3. Foxbridge returns the PDF data with eof: true
  4. Puppeteer calls IO.close({handle: "pdf-stream-123"})

Stream handles are stored in memory and cleaned up on IO.close.

Page.printToPDF → Juggler Page.printToPDF ← {data: base64} stored as stream → returns {data, stream: handle} IO.read({handle}) ← {base64Encoded: true, data: ..., eof: true} IO.close({handle}) ← {} (stream deleted)

BiDi Backend

On the BiDi backend, Page.printToPDF maps to browsingContext.print, which returns the PDF as a base64 string. The same IO streaming mechanism is used.


See also

Last updated on