react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

PDFs render too small treating pts as px

Open chenlijun99 opened this issue 2 years ago • 8 comments

Before you start - checklist

  • [X] I followed instructions in documentation written for my React-PDF version
  • [X] I have checked if this bug is not already reported
  • [X] I have checked if an issue is not listed in Known issues
  • [X] If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo

Description

Not sure if it's a bug or a feature. But when a PDF is rendered at default size using react-pdf, its size differs from the size when using PDF.js's "Actual size" option. Specifically, react-pdf seems to take the values from the view property of PDFPageProxy and treat them as pixel, while they actually mean user points.

Steps to reproduce

  • Simply render a PDF using react-pdf without passing height, width, scale.
  • Open the same PDF using pdf.js (e.g. https://mozilla.github.io/pdf.js/web/viewer.html) and set "Actual Size" as zoom option.
  • Observe that the sizes of the two rendered PDFs differ.

Expected behavior

They should have the same size. In particular react-pdf should consider that the values in view are user points and convert them to pixel appropriately.

Actual behavior

react-pdf treats the values read from view as pixels.

Additional information

No response

Environment

  • Browser (if applicable): Firefox 107.0
  • React-PDF version: v6.2.0
  • React version: 18.2.0
  • Webpack version (if applicable):

chenlijun99 avatar Dec 09 '22 11:12 chenlijun99

+1 I'm getting the same issue and was wondering why it happened. If I create my own custom pdf (from Word), it shows up a little bigger, but still seems small. If I use an "official" PDF from another source, it shows pretty small

aarowman avatar Jan 18 '23 16:01 aarowman

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

github-actions[bot] avatar Apr 24 '23 00:04 github-actions[bot]

This issue was closed because it has been stalled for 14 days with no activity.

github-actions[bot] avatar May 15 '23 00:05 github-actions[bot]

Please re-open this issue - I think the "actual size" is the better user experience default! At a minimum, we should have an option to specify it instead of being forced in the preview mode

aarowman avatar May 15 '23 15:05 aarowman

Please re-open this issue. After checking pdf metadata I can see that react-pdf is treating pts as pixels thus causing the document to not size correctly

ASutrick avatar Sep 27 '23 15:09 ASutrick

I'm reopening this as it indeed looks like we're not sizing PDFs correctly, although:

  • I still don't know why this happens
  • Fix will be treated as breaking change and released with the next major release because of its significance

wojtekmaj avatar Sep 28 '23 13:09 wojtekmaj

Until a fix is found you can multiply your desired scale by 1.33 to get actual document size

ASutrick avatar Oct 02 '23 14:10 ASutrick