question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

While generating pdf, landscape option doesn't work

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:15

github_iconTop GitHub Comments

14reactions
toixcommented, Oct 22, 2019

Have you tried altering the CSS rule @page?

@page {
    size: auto;
}

Edit: You can use the CSS rule only for Puppeteer:

page.addStyleTag(
    {'content': '@page {size: auto}'}
)
11reactions
JandosKhcommented, Nov 2, 2019

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; }’} )

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rotation problem when creating PDF | Adobe Acrobat
Rotation problem when creating PDF · 1. Choose File > Export · 2. In the Export dialog, choose Adobe PDF · 3. When...
Read more >
PDF won't deal with Word landscape pages properly
I tried several things — re-creating the PDF using Acrobat, using Word's PDF option, fiddling with the settings in Acrobat etc. all to...
Read more >
Microsoft Print To PDF Option Changes Page Orientation To ...
1. Open the Tools menu, locate its Pages submenu and choose "Rotate" to open the Rotate Pages dialog box. · 2. Change the...
Read more >
[Solved] Headless Chrome options ignoring landscape mode ...
NET client library was not generating his PDFs in 'landscape' mode while using Headless Chrome. The customer provided all of their C# code ......
Read more >
Landscape mode when printing to pdf - ROOT Forum
hi, In an application, I save the canvas plots as a pdf document using the method: C->Print("C.pdf"); The output file is in portrait...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found