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.

Extra whitespace above the header and below the footer.

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: puppeteer@1.13.0
  • Platform / OS version: OSX 10.11
  • URLs (if applicable):
  • Node.js version: npm@6.8.0

What steps will reproduce the problem?

I have configured a header and footer for the site example.com and I have got the following issue.

Please include code that reproduces the issue.

1 JS code

const puppeteer = require("puppeteer");

(async () => {const browser = await puppeteer.launch({headless:true});

const page = await browser.newPage(); 
var fs = require("fs"); 

await page.goto("https://example.com/"); 

await page.pdf({path: "./output/1.pdf",

 format: "A4",

 displayHeaderFooter:true,
 
headerTemplate:"<div style=' font-size: 28px; width:100%; -webkit-print-color-adjust: exact;height:180px; min-height: 69px;overflow: auto;clear: both;border-bottom: 1px solid #ddd;background: red;' >Header</div>", 

footerTemplate:"<div style=' font-size: 28px;  width:100%; -webkit-print-color-adjust: exact;height:180px; min-height: 69px;overflow: auto;clear: both;border-bottom: 1px solid #ddd;background: red;'> Footer</div>", 

printBackground : true, 

preferCSSPageSize:false,

margin : {top: "120px", bottom : "120px"
} 
} ); 
await browser.close(); })();

What is the expected result?

The pdf with no white space above the header and below footer, with content in the footer

What happens instead?

There is an extra whitespace above the header and below the footer and added to tat the footer is also generated empty without content.

I have attached the output pdf

1.pdf

Issue Analytics

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

github_iconTop GitHub Comments

42reactions
zhmcommented, Mar 21, 2019

You have to override this style using a <style> tag in your header and footer content:

<style>#header, #footer { padding: 0 !important; }</style>
20reactions
vekunzcommented, Jan 16, 2020

Add it directly to you header or footer template:

const header = '<style>#header, #footer { padding: 0 !important; }</style><div class="header" style="padding: 0 !important; margin: 0; -webkit-print-color-adjust: exact; background-color: red; color: white; width: 100%; text-align: left; font-size: 12px;">header of Juan<br /> Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>';
const footer = '<style>#header, #footer { padding: 0 !important; }</style><div class="footer" style="padding: 0 !important; margin: 0; -webkit-print-color-adjust: exact; background-color: blue; color: white; width: 100%; text-align: right; font-size: 12px;">footer of Juan<br /> Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>';

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to remove extra white spaces above the header and ...
I've developed a header and a footer in bootstrap and styled them in CSS. But there's a white space above the header and...
Read more >
How To Hide/Reduce The Blank Space Above Header ...
Code link: https://v815.blogspot.com/2018/11/how-to- remove - blank-space -just- above.htmlTo reduce or hide the gap above and below footer in a ...
Read more >
White space above and below footer | WordPress.org
The white space only appears on mobile and tablet, and only on the single product page. It is both above and below the...
Read more >
How to remove white space below the header and above the ...
You want to remove the white space that is positioned below the header area and above the footer on pages/posts, right? We made...
Read more >
How to remove the white space in the Header and Footer
Please note that since every Shopify theme uses a different coding style, the steps below only apply to the Debut theme as an...
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 Hashnode Post

No results found