mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(pdf): add headerTemplate
and footerTemplate
to available PDF options (#1625)
This patch allows specifying header and footer templates for PDF printing. Fixes #373.
This commit is contained in:
parent
48f5f2ef55
commit
f8040cb2a2
@ -891,6 +891,13 @@ Page is guaranteed to have a main frame which persists during navigations.
|
|||||||
- `path` <[string]> The file path to save the PDF to. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, the PDF won't be saved to the disk.
|
- `path` <[string]> The file path to save the PDF to. If `path` is a relative path, then it is resolved relative to [current working directory](https://nodejs.org/api/process.html#process_process_cwd). If no path is provided, the PDF won't be saved to the disk.
|
||||||
- `scale` <[number]> Scale of the webpage rendering. Defaults to `1`.
|
- `scale` <[number]> Scale of the webpage rendering. Defaults to `1`.
|
||||||
- `displayHeaderFooter` <[boolean]> Display header and footer. Defaults to `false`.
|
- `displayHeaderFooter` <[boolean]> Display header and footer. Defaults to `false`.
|
||||||
|
- `headerTemplate` <[string]> HTML 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
|
||||||
|
- `footerTemplate` <[string]> HTML template for the print footer. Should use the same format as the `headerTemplate`.
|
||||||
- `printBackground` <[boolean]> Print background graphics. Defaults to `false`.
|
- `printBackground` <[boolean]> Print background graphics. Defaults to `false`.
|
||||||
- `landscape` <[boolean]> Paper orientation. Defaults to `false`.
|
- `landscape` <[boolean]> Paper orientation. Defaults to `false`.
|
||||||
- `pageRanges` <[string]> Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
|
- `pageRanges` <[string]> Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
|
||||||
|
@ -711,6 +711,8 @@ class Page extends EventEmitter {
|
|||||||
async pdf(options = {}) {
|
async pdf(options = {}) {
|
||||||
const scale = options.scale || 1;
|
const scale = options.scale || 1;
|
||||||
const displayHeaderFooter = !!options.displayHeaderFooter;
|
const displayHeaderFooter = !!options.displayHeaderFooter;
|
||||||
|
const headerTemplate = options.headerTemplate || '';
|
||||||
|
const footerTemplate = options.footerTemplate || '';
|
||||||
const printBackground = !!options.printBackground;
|
const printBackground = !!options.printBackground;
|
||||||
const landscape = !!options.landscape;
|
const landscape = !!options.landscape;
|
||||||
const pageRanges = options.pageRanges || '';
|
const pageRanges = options.pageRanges || '';
|
||||||
@ -736,6 +738,8 @@ class Page extends EventEmitter {
|
|||||||
const result = await this._client.send('Page.printToPDF', {
|
const result = await this._client.send('Page.printToPDF', {
|
||||||
landscape: landscape,
|
landscape: landscape,
|
||||||
displayHeaderFooter: displayHeaderFooter,
|
displayHeaderFooter: displayHeaderFooter,
|
||||||
|
headerTemplate: headerTemplate,
|
||||||
|
footerTemplate: footerTemplate,
|
||||||
printBackground: printBackground,
|
printBackground: printBackground,
|
||||||
scale: scale,
|
scale: scale,
|
||||||
paperWidth: paperWidth,
|
paperWidth: paperWidth,
|
||||||
|
Loading…
Reference in New Issue
Block a user