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.

Issue with margins when print to PDF

See original GitHub issue

I have a strange issue with page margins when printing to PDF. And it’s most likely Chrome issue.

What steps will reproduce the problem? Just build PDF via Puppeteer: await page.pdf({ path: pdfPath, format: 'A4' });

This issue is also reproduced when you are in Chrome in Print Preview (Ctrl + P).

Case 1: I have a CSS with these styles:

    @page { margin: 3cm 0 2cm; }

Some text is not shown because of margins, it’s like under it (lines 13 and 14 missed). 0

Case 2: But when I set margins to 0 everything is OK:

    @page { margin: 0; }

1

Case 3 When I’m in Chrome’s Print Preview and set Custom Margins (the same 3cm at top and 2 cm at bottom) everything is OK and text is not cut. 2

What is the expected result? Text should be moved to next page as in case 3.

What happens instead? Text is not shown as it is under margins. (see case 1).

Please advise how to fix that.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:13

github_iconTop GitHub Comments

4reactions
initialappscommented, Oct 17, 2020

I struggled with this for awhile and finally got this to work by setting a smaller page size, while setting the margin to zero. @page { size:8in 10in; margin: 0; }

Revisiting this a year and a half later… My prior answer was wrong. I had a lot of competing CSS margins that were making things messy.

After cleaning that up, I simply specified page size and margins in inches and it worked:

@page {
        size: 8.5in 11in; 
        margin: 0.5in;
}
2reactions
pantekx3commented, May 29, 2018

At last, I found out what is the cause of the issue in my case - it was margin-bottom for the first page:

@page:first {
    margin-bottom: 0; 
}

After removing it - everything is OK. @IpShot hope it will also help you if you have similar margin styles 😃 Thanks everybody!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to correct margins when printing a PDF?
In the adobe print set up box, choose "Print to PDF paper size" and select "none" for ...
Read more >
How to Adjust, Set Margins While Printing PDF Documents
If you want to print your PDF without any margins, just open the PDF file and go to the “File” menu and click...
Read more >
How to retain correct margins/page size when converting ...
I've solved this problem in previous versions by simply deselecting print scaling in Microsoft Word or in Distiller. In Word 2010 you do...
Read more >
Extra margin in Excel when saving to PDF
Usually when printing pdf files there is an option for binding and if long side binding is selected the left side margin is...
Read more >
Margins Are Incorrect When Printing to PDF in Finale v27 ...
Margins Are Incorrect When Printing to PDF in Finale v27(macOS Only) · Open a Finale file to be saved as a PDF. ·...
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