Open johnnash03 opened 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.
@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.
@nickythorne The remote url given is correct.The problem lies somewhere else.
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!
@nickythorne Yes that's what I've done so far. I'll maybe send a PR to have this feature directly in this lib.
Is there an updated solution to this issue?
@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
Hey! This solution worked nicely for me.
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
@pgonzalez-santiago you can use normal webView with google pdf uri http://docs.google.com/gview?embedded=true&url=' + this.state.pdfPath
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}/>