Read PDF with Expo (ios & android)


#1

Hi,

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

Example: https://expo.io/@xcarpentier/rn-pdf-reader-example

Code: https://github.com/xcarpentier/rn-pdf-reader-js

PRs are welcome :slight_smile:


#2

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


#3

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…


#4

Thanks for creating that library ! You the real MVP!


#5
   <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?


#6

not sure you can read pdf from assets…


#7

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)


#8

Also, on iOS, I ran into this issue:


#9

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


#10

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.