Support get the size of the pdf when Pdf loaded? #1535
Replies: 6 comments 4 replies
-
You can pass import { Document } from 'react-pdf';
// In your react component
handleLoadSuccess = async (pdfObject) => {
// If you want to get the dimension for page 1 (1-indexed)
const page = await pdf.getPage(1);
console.log(page.width);
console.log(page.height);
};
render() {
<Document
onLoadSuccess={handleLoadSuccess}
// Other props
/>
}; Once you get the height/width, you'll be able to figure out if it's A3, A4, A5 or letter. Similarly you can also pass your callback as the |
Beta Was this translation helpful? Give feedback.
-
It seems that height and width are not accessible anymore on the page object obtained through getPage. Have they been removed ? |
Beta Was this translation helpful? Give feedback.
-
Just tested that and you can totally still get width and height from page object obtained from |
Beta Was this translation helpful? Give feedback.
-
I have to do this
|
Beta Was this translation helpful? Give feedback.
-
Just hit the same problem. Using typescript, |
Beta Was this translation helpful? Give feedback.
-
In latest versions, on every function I execute in onLoadSuccess callback I receive the following error: This makes impossible for us to get the height and width of the page, right? |
Beta Was this translation helpful? Give feedback.
-
hello,
is there a way to find page size like A3, A4, A5 ..., in react pdf?
thank you!
payam
Beta Was this translation helpful? Give feedback.
All reactions