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 creation pixel sizes causes layout to change

See original GitHub issue

Hi,

When creating PDFs from a responsive web page, lets say the page has a css rule to show a narrower version below 1024 pixels screen width and we supply width: "1024px" to pdf function. The rule should not apply on this case however it does and the layout changes in generated pdf.

Only when the width parameter is 4/3 of the actual width of viewport, then the pdf has exact same layout of given viewport width. This seems to be something related to an inches / points confusion somewhere (96 pixels per inch, 72 pixels per point. 96/72 = 4/3)

So, when I provide 1365px as pdf width I get the exact representation of the page at 1024px viewport width. Anything below 1365px, page acts like the viewport is below 1024px and applies the appropriate responsive css rules.

I’m not sure if this is an upstream bug or something else though. Margins are set to 0 btw.

Any ideas?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:19
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
erasmuswillcommented, Sep 30, 2021

I had the same issue, I fixed it by doing this:

   const convertPixelToInches = (value, dpi) => {
      let inches = value/ dpi;
      return `${inches}in`; // Calculate inches value and round it up.
    }
    const pageWidth = convertPixelToInches(req.body.evidenceWidth, 72);
    const pageHeight = convertPixelToInches(realPageHeight < req.body.evidenceHeight ? req.body.evidenceHeight : realPageHeight, 96);

And passing the values as width and height. @aslushnikov @rossj The only thing I’d like to understand now is why the dpi for the width and height need to be different for the width an height, where, if I return them from headless Chromium are 96 for height and width.

What is req.body.evidenceWidth , req.body.evidenceHeight and realPageHeight , supposed to be?

@jbprat really curious about this too

wisdom_of_the_ancients

2reactions
ghostcommented, May 9, 2020

I had the same issue, I fixed it by doing this:

   const convertPixelToInches = (value, dpi) => {
      let inches = value/ dpi;
      return `${inches}in`; // Calculate inches value and round it up.
    }
    const pageWidth = convertPixelToInches(req.body.evidenceWidth, 72);
    const pageHeight = convertPixelToInches(realPageHeight < req.body.evidenceHeight ? req.body.evidenceHeight : realPageHeight, 96);

And passing the values as width and height.

@aslushnikov @rossj The only thing I’d like to understand now is why the dpi for the width and height need to be different for the width an height, where, if I return them from headless Chromium are 96 for height and width.

What is req.body.evidenceWidth , req.body.evidenceHeight and realPageHeight , supposed to be?

Read more comments on GitHub >

github_iconTop Results From Across the Web

When creating PDF from an image, what determines the ...
If you want to accurately display sizes in Acrobat you need to alter Acrobat's preferences. If you go to Preferences > Page Display...
Read more >
About a PDF format (understanding and working ... - GdPicture
The physical size of the page won't change, but depending on the zoom level, the number of pixels used to represent it, will...
Read more >
PDF format and size guidelines - Flipsnack Help Center
Failed conversion because one or more pages might be too complex, probably containing too many vector objects. How do you know if you...
Read more >
Adobe PDF conversion settings, Acrobat
Replaces an entire area with a pixel selected from that sample area, at the specified resolution. Causes faster conversion time than ...
Read more >
Generate Winnovative PDF to be a certain width/height pixel ...
The PDF page A4 potrait size is 595 x 842 points and the HTML viewer width corresponding to the 595 points is 595...
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