Closed bomalley closed 8 years ago
Sorry to be so persistent, but I'm really struggling here. Can anyone help?
Thanks in advance!
You should try to get the bundle path
Take a look at this package https://github.com/johanneslumpe/react-native-fs
RNFS.MainBundlePath
+ '/My.pdf'
That's very helpful, thank you @sibeliusseraphini.
Unfortunately that only seems to work if the PDF is in the files
folder. If it's bundled in your APK, I can't see any way to get at it. Am I just missing something obvious?
@bomalley how do you get the path information using Object-C/Swift on iOS, and in Java on Android?
@sibeliusseraphini I'm trying to use the react-native-fs
you recommended. It will allow me to get the data folder, but not the bundle/package folder, which is the problem.
have you tried MainBundlePath
? What is the result of RNFS.readDir
?
In iOS you can use this to get the bundlePath:
NSString *path = [[NSBundle mainBundle] pathForResource:@"SomeFile" ofType:@"jpeg"];
Okay, it took A LOT of tinkering, but I've finally figured out how to display a PDF that is pre-bundled in your Android APK. I documented the process on my website: How to display a PDF in React Native
In a nutshell:
react-native-fs
to get an absolute URL to the PDF.react-native-pdf-view
to show the PDF.@bomalley for now your hack works fine, but I think react-native-fs
should handle this problem.
Try to submit a PR there using the code from your article :+1:
@sibeliusseraphini Will do, though probably not until this weekend.
Can you please show an example that refers to a PDF in your project bundle? I'm stuck on the 'absolute path' for the
src
attribute.if I have this layout, what should be in my src attribute?
/index.android.js /My.pdf
Thanks.