From 12e3510eca7da8d54b79d8d9226216e17f8474cf Mon Sep 17 00:00:00 2001 From: Fred Chasen Date: Thu, 26 Jul 2018 18:51:44 -0700 Subject: [PATCH] feat(page): add 'preferCSSPageSize' to page.pdf options (#2928) Fixes #1963. --- docs/api.md | 1 + lib/Page.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/api.md b/docs/api.md index 3b88648b..4568a2ba 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1277,6 +1277,7 @@ Page is guaranteed to have a main frame which persists during navigations. - `right` <[string]> Right margin, accepts values labeled with units. - `bottom` <[string]> Bottom margin, accepts values labeled with units. - `left` <[string]> Left margin, accepts values labeled with units. + - `preferCSSPageSize` <[boolean]> Give any CSS `@page` size declared in the page priority over what is declared in `width` and `height` or `format` options. Defaults to `false`, which will scale the content to fit the paper size. - returns: <[Promise]<[Buffer]>> Promise which resolves with PDF buffer. > **NOTE** Generating a pdf is currently only supported in Chrome headless. diff --git a/lib/Page.js b/lib/Page.js index 80380077..aa6e6513 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -889,6 +889,7 @@ class Page extends EventEmitter { const marginLeft = convertPrintParameterToInches(marginOptions.left) || 0; const marginBottom = convertPrintParameterToInches(marginOptions.bottom) || 0; const marginRight = convertPrintParameterToInches(marginOptions.right) || 0; + const preferCSSPageSize = options.preferCSSPageSize || false; const result = await this._client.send('Page.printToPDF', { landscape: landscape, @@ -903,7 +904,8 @@ class Page extends EventEmitter { marginBottom: marginBottom, marginLeft: marginLeft, marginRight: marginRight, - pageRanges: pageRanges + pageRanges: pageRanges, + preferCSSPageSize: preferCSSPageSize }); const buffer = Buffer.from(result.data, 'base64'); if (options.path)