Read PDF with Expo (ios & android)

Hi,

Just a small lib to display PDF without ejecting and inner app with webview: iOS and ANDROID ! :tada:

Example: Expo

Code: GitHub - xcarpentier/rn-pdf-reader-js: 📄 PDF reader in JavaScript only for Expo - Android & iOS capable

PRs are welcome :slight_smile:

12 Likes

WOW! your concept is bigger than just integrating react-pdf… kudos!

1 Like

Yes for android I use react-pdf (pdf.js) but not for iOS that directly display PDFs.

I’m currently working on the improvement of android display, still not perfect…

Thanks for creating that library ! You the real MVP!

1 Like
   <View style={styles.container}>
        <PDFReader
          source={{ uri: "file:///assets/abc.pdf" }}
        />
      </View>

I’m trying to view pdf on android. but it doesn’t work. what is wrong with this? could you please help me?

not sure you can read pdf from assets…

Thank you so much for uploading this module!

When I tried the example of
<PDFReader source={{ uri: "http://gahp.net/wp-content/uploads/2017/09/sample.pdf" }} />

I ran into this error on Android:

Any ideas?

(btw, I’m running Expo 31.0.2)

Also, on iOS, I ran into this issue:

I’m trying to figure out the source of this currently. From my initial research, I found that RN changed how they load the URI param to use resovleAsset() which comes from Image, but I haven’t personally looked into what method they used before to see if it was a base64 or url piece… I don’t know what commit this landed in, so I haven’t opened an issue for the RN team yet. But it is actually an issue that will have to happen at the RN team level.

For the time being, @xcarpentier we’ll need to find an alternative to load pdfs in a webview on iOS with rn 57+.

EDIT: I’ve opened up a RN issue for this hopefully it gets some sort of traction. https://github.com/facebook/react-native/issues/22416

Ok good news bad news, bad news is that the FB RN team will not be patching their Webview and will rely upon the community driven version which is currently not in Expo.

Good news is that there is a Canny request for this module to get added, I’ve made a comment and got the attention of @bacon so we might see progress with the updated Webview getting added to Expo.

@xcarpentier I’ll see if I can find time to make a PR for this on your repo in the upcoming week. I’ve got finals to prep for though so it might be a while before I can make time. All that needs to be changed is probably to add a check if ios = true and base64 = true then copy the android webpack view to the ios webpack and display it otherwise let the ios webview handle the view.

1 Like

Hi, should be fixed in latest lib version v0.2.1! :slight_smile: :tada:

3 Likes

You, sir, deserve a drink. I have been wrestling with this off and on for 3 weeks and this update worked first try!! Thank you!!!

1 Like

Hi @xcarpentier,
Thanks for creating this lib.
I can load the PDF but the navigation only works when clicking on prev/next button and not when scrolling. Any idea?
Regards.

2 Likes

This no longer works in SDK 35 as [xcarpentier/rn-pdf-reader-js] uses UIWebView.

1 Like

Amazing library, I could change my code and render a pdf file in less than a minute. Thank you so much.

1 Like

this is fixed :tada:

you are now able to activate the scroll withScroll prop

This should be fixed

1 Like

How to save PDF ?

1 Like

Could you elaborate on what you’re trying to do? If you’re using rn-pdf-reader-js then you must already have the source, so you can probably save it using FileSystem.downloadAsync()