Faisal Saud
Faisal Saud

Reputation: 21

How to get the total number of pdf pages in react-native without viewing the document

I want to know how to get the total number of pages without the need to view the document.. I am using react-native-document-picker , rn-fetch-blob and eact-native-firebase to get the file and upload it this is for me successful .. but I want to know what is the number of pages in the pdf document I looked in libraries such as react-native-pdf , react-native-view-pdf, react-native-pdf-lib

but seems none of them will get me the number of pages without the need to view the file .. in my case, before uploading the file I need to verify the number of pages.. I would appreciate it if you help me in this matter I really do not know where to start here

Thanks

Upvotes: 2

Views: 2112

Answers (1)

Klaz
Klaz

Reputation: 131

You could achieve this using react-native-pdf, without rendering the pdf itself. What I am saying is this, while you use the Pdf component, pass only the source and onLoadComplete props to it. onLoadComplete always returns the number of pages and you could use this by maybe updating a state with the value.

e.g

<Pdf source={{uri: path}} onLoadComplete={numOfPages => this.setState({numOfPages}) /> 

Upvotes: 4

Related Questions