Reputation: 41
I wanna open a pdf when a button click. Also, I don't use react-native-pdf because I got an error in linking it with react-native. So, now I try to show pdf using rn-pdf-reader-js. It works well in loading pdf from the web, but can't load the local file. How can I fix it? Here is my code.
<PDFReader
source={{ uri: "file:///D:/test/Angular.pdf" }}
/>
error: "Invalid response for blob";
Upvotes: 2
Views: 4971
Reputation: 129
The question is quite generic since you don't mention what device you are using. I personally came across the same errors and trouble as you are describing trying to accomplish pdf loading on an ANDROID device.
After much fiddling and mainly trial and error, I finally managed to come up with a solution. I'm glad to share it with whom ever is experiencing similar roadblocks.
'react-native-pdf' is the library you are looking for (react-native-pdf documentation). Follow the instructions CAREFULLY. Here are some key notes from documentation to notice:
'android/app/src/main/assets/pdf/'
const source = {uri:'bundle-assets://yourdocument.pdf'};
Upvotes: 4
Reputation: 564
You're trying to load a from from your computer's D: drive. In most cases, your emulator (or device) doesn't have any access to that drive. And the resulting issue is that it's trying to look for a path that doesn't exists in its own drive.
You should move the file to your emulator's (or device's) storage and attempt to load it from there with a path usable by your app.
Be careful, on some platforms / OS, you'll need permissions to access user files, like Downloads folder, image gallery...
Stuff to read to help you out:
Upvotes: 0