[PDF] Using different margin bottom on first page doesn't work
See original GitHub issueSteps 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:
- Created 5 years ago
- Reactions:5
- Comments:17 (1 by maintainers)
Top 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 >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
Any updates on this?
@hakimio This is what I tried first. It results in exactly the same (wrong) PDF. Therefore I assume, that the
margin
option of thepage.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 totrue
, themargin-bottom
gets ignored. This happens with both, using regular CSS as well as using themargin
option of thepage.pdf()
method.