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.

puppeteer margins:none equivalence of chrome print

See original GitHub issue

Even when i set margins 0 all. I am keep getting default margins my @page{ margin: 0 !important; padding: 0 !important; } i was searching long time for this and did found nothing that would help.

^1.9.0 puppeteer ubuntu 18.04 10.15.1 node

this.browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
const page = await this.browser.newPage();
// @ts-ignore
await page._emulationManager._client.send('Emulation.setDefaultBackgroundColorOverride', {
  color: {
    r: 0,
    g: 0,
    b: 0,
    a: 0
  }
});

await page.goto(
  'https://google.com',
  {
    waitUntil: 'networkidle0'
  }
);
await page.pdf({
  path: '/home/pdf.pdf',
  printBackground: true,
  displayHeaderFooter: true,
  format: 'A4',
  preferCSSPageSize: true,
  headerTemplate: '<span></span>',
  footerTemplate: '<span></span>',
  margin: {
    left: '0',
    right: '0',
    top: '0',
    bottom: '0'
  };
});```

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Denhellcommented, Mar 5, 2020

use

body {
    margin: 0;
}
2reactions
nflorentincommented, Jul 15, 2019

For me, this css did the trick:

@page {
  size: A4 portrait;
  margin: 0;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Puppeteer ignores some CSS rules to print PDF when I used ...
I find the puppeteer always ignore some CSS rules which is in @media print. Here is my env: Puppeteer version: 1.11. Platform /...
Read more >
Advanced Options - Headless Chrome - Api2Pdf
Attribute Type Description landscape Boolean Paper orientation. Defaults to false. displayHeaderFooter Boolean Display header and footer. Defaults to false. printBackground Boolean Print background graphics. Defaults to...
Read more >
Puppeteer generate PDF from HTML - Pocket Admin
This function generates a pdf document from html markup. Generating a pdf is currently only supported in Chrome headless! Generation pdf; Save ...
Read more >
puppeteer page break pdf - I VIAGGI DI REMO
Download Puppeteer Tutorial (PDF Version) Previous Page Print Page Next Page ... It can also be configured to use full (non-headless) Chrome or...
Read more >
page-break-after - CSS: Cascading Style Sheets | MDN
It's the page placed on the left side of the spine of the book or the back side of the page in duplex...
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