cnjon / react-native-pdf-view

React Native PDF View
MIT License
404 stars 167 forks source link

Cannot open pdf with url in android #40

Open johnnash03 opened 7 years ago

johnnash03 commented 7 years ago

return <PDFView ref={(pdf)=>{this.pdfView = pdf;}} path={"http://www.orimi.com/pdf-test.pdf"} onLoadComplete = {(pageCount)=>{ this.pdfView.setNativeProps({ zoom: 1.5 }); }} style={styles.pdf}/>

nickythorne commented 7 years ago

The error is caused by an incorrect file path being passed to the PDFView native component. Under the hood, the component instantiates a new File(path) object which the specified prop value. If the file cannot be found then this error is what's bubbled up to RN.

I had this same error when passing an incorrectly formatted URL for the path property. In my case, my URL was prefixed with file:// which was unnecessary, upon removing this the error disappeared.

jr-k commented 7 years ago

@nickythorne I've this error too, the URL is ok, just try with https://www.u-paris2.fr/sites/default/files/pdf.pdf it doesn't work with a remote URL.

For a local link I agree, you have to delete file:/// prefix.

johnnash03 commented 7 years ago

@nickythorne The remote url given is correct.The problem lies somewhere else.

nickythorne commented 7 years ago

I had a similar scenario, whereby I had to read a remote PDF. Upon looking at the code, I discovered that the module only handles local files and asset files by default.

The solution in my case was to use it in combination with react-native-fs. This library comes with a downloadFile method which can be used to download your external file first before passing the local path to react-native-pdf-view.

Hope this helps!

jr-k commented 7 years ago

@nickythorne Yes that's what I've done so far. I'll maybe send a PR to have this feature directly in this lib.

DeveloperAlly commented 7 years ago

Is there an updated solution to this issue?

DeveloperAlly commented 7 years ago

@nickythorne @jr-k could you please provide some example code? I have tried using Fetch-Blob to download the file locally and then display it with no results. Your help would be much appreciated

webmariner commented 7 years ago

Hey! This solution worked nicely for me.

pgonzalez-santiago commented 7 years ago

Is there a way to open a PDF without download it? Open pdfs in Webview are working perfectly for me on iOs but not in android.5.0

flieks commented 7 years ago

@pgonzalez-santiago you can use normal webView with google pdf uri http://docs.google.com/gview?embedded=true&url=' + this.state.pdfPath