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.

[PDF] Using different margin bottom on first page doesn't work

See original GitHub issue

Steps to reproduce

Environment:

  • Puppeteer version: 1.3.0
  • Platform / OS version: Ubuntu 14.04
  • Node.js version: 7.6.0

Code:

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://github.com/GoogleChrome/puppeteer', {waitUntil: 'networkidle2'});
await page.addStyleTag({
    content: '@page:first {margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px;}'
});
await page.pdf({
    path: 'test.pdf',
    format: 'A4',
    displayHeaderFooter: true,
    headerTemplate: '<div style="font-size:16px;width:100%;text-align:center;">HEADER</div>',
    footerTemplate: '<div style="font-size:16px;width:100%;text-align:center;">FOOTER</div>',
    margin: {top: '50px', right: '10px', bottom: '50px', left: '10px', }}
);
await browser.close();

Expected result: The first page should have no margins (and therefore hide the header and footer), while all following pages should have the specified margin and display the header and footer.

Actual result: The header is properly displayed on all pages except the first one. The footer, however, is only displayed on the last page. It seems that the margin bottom isn’t applied properly.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
spiritixcommented, May 19, 2020

Any updates on this?

2reactions
spiritixcommented, May 24, 2018

@hakimio This is what I tried first. It results in exactly the same (wrong) PDF. Therefore I assume, that the margin option of the page.pdf() internally produces CSS as well.

However, I just discovered something really interesting. Have a look at the following two PDF files:

No footer/header: https://drive.google.com/open?id=12jshVH0_hz3S-JK-wCqxxrs3h0IuDDDu With footer/header: https://drive.google.com/open?id=1IcF2PQ1MC5jOr3WsVtj1KCQKt57Qriqt

As you can see, as soon as I set the displayHeaderFooter option to true, the margin-bottom gets ignored. This happens with both, using regular CSS as well as using the margin option of the page.pdf() method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Different margin bottom for first page TCPDF - Stack Overflow
This can be achieved by initially setting a larger margin with SetAutoPageBreak(), then setting it to a smaller margin after drawing the ...
Read more >
Different margins on different pages - Essential Objects
We have a scenario where we need to have different margins on the first and last pages (left/right and top/bottom).
Read more >
Table does not fill 100% of the page when all margins set to 0 ...
Hi all. I am trying to make a 2x1 Table completely fill two A4 pages in portrait orientation - left-to-right, and top-to-bottom.
Read more >
2 Ways to Change Margin on One Page in MS Word Method 1
Go to the Layout tab and click the Margins drop-down menu. Once the different preset margin formats are displayed, select one from the...
Read more >
How to have different margins on the first page
The secret is that, when you increase the size of the header (or footer) beyond the top (or bottom) margin, it will push...
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