← Back to Page domain

Page.printToPDF

Print page as PDF.

Domain: Page stable

Parameters

NameTypeDescription
landscape (optional)booleanPaper orientation. Defaults to false.
displayHeaderFooter (optional)booleanDisplay header and footer. Defaults to false.
printBackground (optional)booleanPrint background graphics. Defaults to false.
scale (optional)numberScale of the webpage rendering. Defaults to 1.
paperWidth (optional)numberPaper width in inches. Defaults to 8.5 inches.
paperHeight (optional)numberPaper height in inches. Defaults to 11 inches.
marginTop (optional)numberTop margin in inches. Defaults to 1cm (~0.4 inches).
marginBottom (optional)numberBottom margin in inches. Defaults to 1cm (~0.4 inches).
marginLeft (optional)numberLeft margin in inches. Defaults to 1cm (~0.4 inches).
marginRight (optional)numberRight margin in inches. Defaults to 1cm (~0.4 inches).
pageRanges (optional)stringPaper ranges to print, one based, e.g., '1-5, 8, 11-13'. Pages are printed in the document order, not in the order specified, and no more than once. Defaults to empty string, which implies the entire document is printed. The page numbers are quietly capped to actual page count of the document, and ranges beyond the end of the document are ignored. If this results in no pages to print, an error is reported. It is an error to specify a range with start greater than end.
headerTemplate (optional)stringHTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: - `date`: formatted print date - `title`: document title - `url`: document location - `pageNumber`: current page number - `totalPages`: total pages in the document For example, `<span class=title></span>` would generate span containing the title.
footerTemplate (optional)stringHTML template for the print footer. Should use the same format as the `headerTemplate`.
preferCSSPageSize (optional)booleanWhether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size.
transferMode (optional)stringreturn as stream
generateTaggedPDF (optional)booleanWhether or not to generate tagged (accessible) PDF. Defaults to embedder choice.
generateDocumentOutline (optional)booleanWhether or not to embed the document outline into the PDF.

Returns

NameTypeDescription
datastringBase64-encoded pdf data. Empty if |returnAsStream| is specified. (Encoded as a base64 string when passed over JSON)
streamIO.StreamHandleA handle of the stream that holds resulting PDF data.

Example Request

{
  "id": 1,
  "method": "Page.printToPDF"
}

Example Response

{
  "id": 1,
  "result": {
    "data": "base64-encoded-data...",
    "stream": "stream-value"
  }
}

Usage in Node.js

const result = await send('Page.printToPDF');
console.log(result);
// {"data": "base64-encoded-data...", "stream": "stream-value"}