-
-
Notifications
You must be signed in to change notification settings - Fork 885
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
Page's originalHeight is zero for some pdf pages #672
Comments
This looks like a sensible approach. I wonder if we could generate some PDFs to create unit tests for these cases. This would give me much more confidence implementing this fix. If anyone encountered a similar issue and can share the PDF having such issue, it'd be much appreciated. |
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. |
This issue was closed because it has been stalled for 14 days with no activity. |
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. |
This issue was closed because it has been stalled for 14 days with no activity. |
First of all, really appreciate everyone who contributes to this project 🙇 .
Our team recently encountered an issue with getting the pages' width and height. To be more specific, we have a custom callback function that's passed as the
onRenderSuccess
prop to the<Page />
component. In that callback, we access the parameter that passed to the callback to get the dimensional information of the page such asheight
,width
, etc.Something like this:
However we found out for very little pdfs, the
pageData.height
gives us0
and so ispageData.originalHeight
. Even if the page renders correctly without any error in the console.After some digging, we found the parameter passes to
onRenderSuccess
prop is generated bymakePageCallback()
inutils
:react-pdf/src/Page/PageCanvas.jsx
Line 59 in 2df1e24
Inside
makePageCallback()
, it gets the page's original width bythis.view[2]
and original height bythis.view[3]
, then times the scale to get the width and height respectively.react-pdf/src/shared/utils.js
Lines 120 to 126 in 2c0e179
The
view
is an array with four entries representing the "mediaBox" of the current page (https://github.com/mozilla/pdf.js/blob/e389ed6201df7955147dafda3a6813fff8ca5934/src/core/document.js#L173-L191).Conventionally, the first two numbers are the lower left x and y coordinates, and the last two numbers are the upper right x and y coordinates.
However, according to this pdf spec by Adobe (section 7.9.5), it's also acceptable to specify the upper left x and y, and lower right x and y. It also recommends applications to take this into consideration.
We verify that's the reason for some pages' originalHeight to be zero by checking the
view
property. It gives us something like[0, 824.400024, 578.159973, 0]
. Which we believe the first two numbers are the upper left x and y coordinates, and the last two numbers are lower left x and y coordinates.I wonder has anybody else also encountered this issue? My suggestion for the fix will probably be updating
makePageCallback()
to:Does this sound like the right approach? I'm by no means an expert of pdf. Any feedback or suggestion are definitely welcome. Thank you for your time!
Due to some privacy issue, I'm not able to provide an example pdf. Apologize in advance.
The text was updated successfully, but these errors were encountered: