-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extra whitespace above the header and below the footer. #4132
Comments
You have to override this style using a <style>#header, #footer { padding: 0 !important; }</style> |
Not working for me:
In which file should this code be added? |
Add it directly to you header or footer template:
|
Thanks! Working! |
Hi, Any suggestions how to set margins of the footer / header in cm same as for the main document ? |
@R00118189 Good question. Currently working on the same. Let me know if you found a way :) EDIT: I found this article: https://nathanfriend.io/2019/04/15/pdf-gotchas-with-headless-chrome.html Maybe this helps you to resolve this issue. Especially section: https://nathanfriend.io/2019/04/15/pdf-gotchas-with-headless-chrome.html#headers-and-footers-require-explicit-margins-to-be-visible |
Bhavu it's working...Thank you |
@dasheck0 still trying - the margins as cm don't work in the header (1cm translates to 13mm when PDF opened in illustrator, note the main body margin is 10mm as intended) also is there any way to use fonts in the header and footer if we cant have external links? |
Hey! I worked on this bug during the whole day, and I find some solutions for all these space bugs. I'll try to provide some explanation (or at least some documentation) to keep a trace of everything for the future (and possible fixes). it can be good to add these tricks somewhere in the documentation. Padding after the header and before the footerThis is the default style provided by Chrome with print_header_footer_template_page.html. You can solve this by adding :
This style must be added in the Padding in the contentStrangely, the default
This one must be in the CSS of the document which will be printed. Compute the header and the footer with correct cm sizesThis one gives me some headache. The bug seems caused by an auto-scaling of 1.33f (see here). So we can fix it by computing our header/footer in a bigger size. In our case, we work with an A4 document (21x29.7cm). Compute your
By doing this, you can get the same result than an HTML computed header. I hope it will help some people to create their documents. :) |
The scaling solution by @AamuLumi works really well, thanks! One little modification: For an A4 document the width should be 28cm, not 27.93cm (21 x 1.333333333 = 27.99999993). |
Guys any of the solutions don't seem to be working. |
Started with trying to figure out the spacing above and below too, then went on to figure out the scaling issue.
#header, #footer {
padding: 0 !important;
transform: scale(0.75) !important;
transform-origin: top left;
height: 100% !important;
position: fixed;
} While the transform scale alone would just make the width smaller, setting |
Easier: #footer, #header {
all: unset;
} You might need to toss in an |
headerTemplate: Puppeteer: |
Since Chrome 117+ it's fixed. No need to scale the content with 1.333f |
Steps to reproduce
Tell us about your environment:
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
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
The text was updated successfully, but these errors were encountered: