Page.pdf does not honor width and height parameters and is missing content
See original GitHub issue- Puppeteer version: 1.9
- Platform / OS version: ubuntu-xenial-16.04-amd64-server-20180627
- Node.js version: 6.4.1
What steps will reproduce the problem?
Here is code that uses Page.pdf()
and Page.screenshot()
to capture a single-page web application and write the browser window contents to PDF- and PNG-formatted files for comparison:
'use strict';
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--start-maximized'
],
timeout: 10000
});
var page = await browser.newPage();
await page.setViewport({
width: 1024,
height: 1280,
deviceScaleFactor: 1
});
await page.emulateMedia('screen');
const url = 'http://higlass.io/app';
await page.goto(url, {
waitUntil: ['load', 'domcontentloaded', 'networkidle2', 'networkidle0']
});
await page.pdf({
path: 'localPuppeteerTest.pdf',
width: '1024px',
height: '1280px',
pageRanges: '1-1'
});
await page.screenshot({path: 'localPuppeteerTest.png', fullPage: true});
await browser.close();
})();
What is the expected result?
The expected result is what is shown in the PNG screenshot:
What happens instead?
While the PNG is rendered correctly, the PDF rendering appears to ignore the specified page viewport dimensions and is missing content:
The PNG renderer appears to respect the page viewport dimensions, and contains all content (such as the element to the right of the “HiGlass” title).
Ideally, the PDF output should match the PNG output in respect to specified dimensions and content.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:12
- Comments:14
Top Results From Across the Web
Why is dompdf not honoring the specified page size?
I've tried it and it doesn't work. The actual issue here is that no matter how one sets the paper size, the PDF...
Read more >Scale or resize printed pages in Acrobat and Reader
Automatically scale to fit paper. Acrobat can size the pages of a PDF to fit the selected paper size. Choose File > Print....
Read more >CSS Paged Media Module Level 3 - W3C
Abstract. This CSS module specifies how pages are generated and laid out to hold fragmented content in a paged presentation.
Read more >PDF::Table - metacpan.org
There are no required parameters. You may pass $pdf, $page, $data, and %options; or can defer this until the table() method invocation (the...
Read more >pdf2json - npm
PDF file parser that converts PDF binaries to text based JSON, powered by porting a fork of PDF.JS to Node.js. Latest version: 3.0.1, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am experiencing a similar issue.
produces a PDF with dimensions 458 x 594.
Settings the size via
@page
css produces the same result. Setting the viewport to 612 x 792 also does not fix the issue.To me it feels like the
width
,height
anddefaultViewport
options are completely ignored.Seems like a DPI of
96
is assumed in the conversion from px to inches here: https://github.com/puppeteer/puppeteer/blob/9923e56b3ed05cde014c0047a4f65fef7749ebb0/lib/Page.js#L1267Whereas some machines may default to a DPI of
72
when calling thePage.printToPDF
method here: https://chromedevtools.github.io/devtools-protocol/tot/Page#method-printToPDF. Perhaps a workaround for now is to scale it up before printing: