react-native-pdf-view icon indicating copy to clipboard operation
react-native-pdf-view copied to clipboard

Cannot open pdf with url in android

Open johnnash03 opened this issue 8 years ago • 10 comments

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}/>

johnnash03 avatar Jan 24 '17 04:01 johnnash03

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 avatar Jan 24 '17 14:01 nickythorne

@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.

jr-k avatar Jan 25 '17 18:01 jr-k

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

johnnash03 avatar Jan 27 '17 08:01 johnnash03

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 avatar Jan 27 '17 09:01 nickythorne

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

jr-k avatar Jan 27 '17 09:01 jr-k

Is there an updated solution to this issue?

DeveloperAlly avatar Apr 09 '17 11:04 DeveloperAlly

@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

DeveloperAlly avatar Apr 16 '17 03:04 DeveloperAlly

Hey! This solution worked nicely for me.

webmariner avatar Apr 21 '17 12:04 webmariner

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 avatar Jul 05 '17 10:07 pgonzalez-santiago

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

flieks avatar Aug 31 '17 12:08 flieks