puppeteer: While generating pdf, landscape option doesn't work
Steps to reproduce
Tell us about your environment: We are trying to generate pdf using puppeteer. Previously we had the landscape option working on Puppeteer 1.5.0 and node 8.9.4. But, after we moved around the code and updated the node and puppeteer versions to 8.15.0 and 1.11.1 respectively, the landscape option tends to generate a portrait instead of a landscape.
- Puppeteer version: 1.11.1
- Platform / OS version: ubuntu
- URLs (if applicable):
- Node.js version: 8.15.0
Please include code that reproduces the issue.
function generatePDF(html, options) { // options has landscape param set to true or false browser = await puppeteer.launch({ args: this.puppeteerArgs }); page = await browser.newPage(); const session = await page.target().createCDPSession();
await session.send('DOM.enable');
await session.send('CSS.enable');
await page.goto(`data:text/html,${html}`, { waitUntil: 'networkidle2' });
this.logger.debug('generatePDF - creating pdf buffer..');
const buffer = await page.pdf(options);
await page.close();
await browser.close();
return buffer;
} What is the expected result? generates a landscape view
What happens instead? generates a portrait view
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 12
- Comments: 16
Have you tried altering the CSS rule
@page?Edit: You can use the CSS rule only for Puppeteer:
I’m using PuppeteerSharp v1.20.0. I confirm that landscape option doesn’t work. Explicitly setting page width & height didn’t work also. However, using page.addStyleTag worked for me. You can try page.addStyleTag( {‘content’: ‘@page { size: A4 landscape; }’} )
Seems to be working fine for me. The code that I used:
This generates a landscape oriented PDF for me. If I leave out the
landscape: truein the options const, I get a portrait oriented PDF.What I noticed is, that if you provide
widthandheightin the options, the landscape is not taken into account. However, when usingformat, the orientation is working just fine 😃Versions:
We had that issue today, but we got it working by calling
await page.emulateMedia('screen');before generating the PDF. After that,landscape : truewas working.The same problem here,
landscape: trueis not working…I’m having the same issue with:
Even if I set the
landscapeoption to true,page.pdfstill generates a portrait oriented PDF.Good morning, everyone
CSS
Node.js
I hope this helps.
+1 same here, landscape not working.