rumax / react-native-PDFView

📚 PDF viewer for React Native
MIT License
300 stars 92 forks source link

Pdf File not found #238

Open mamta-deswal opened 2 years ago

mamta-deswal commented 2 years ago

I'm using react-native-fs for downloading the pdf and saving it.

let url = 'http://samples.leanpub.com/thereactnativebook-sample.pdf';

const getPdfName = () => { return url.split('/').pop(); };

RNFS.downloadFile({ fromUrl: url, toFile: ${RNFS.DocumentDirectoryPath}/${getPdfName()}, }).promise.then(r => { let path = ${RNFS.DocumentDirectoryPath}/${getPdfName()}; setFilePath(path); });

const resourceType = 'file'; const resources = { file: 'thereactnativebook-sample.pdf', };

<PDFView fadeInDuration={250.0} style={styles.pdfStyle} resource={resources[resourceType]} resourceType={resourceType} onLoad={() => console.log(PDF rendered from ${resourceType})} onError={error => console.log('Cannot render PDF', error)} />

Getting error 'Pdf file not found. While code works fine with URL-type resources.

Version:- "react": "18.1.0", "react-native": "0.70.0",

rumax commented 2 years ago

Hi @mamta-deswal , I do not know react-native-fs, but what is DocumentDirectoryPath? Because looking into your example you give

file: 'thereactnativebook-sample.pdf',

and if you look to demo project, that is the way to define path: https://github.com/rumax/react-native-PDFView/blob/master/demo/src/resources.ts#L19

so what you need is absolute path, or you can also try to debug it and check what you actually get in

https://github.com/rumax/react-native-PDFView/blob/master/android/src/main/java/com/rumax/reactnative/pdfviewer/PDFView.java#L130

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.