I’m working on a React Native project using Expo Go, and I need to display PDF files within the app.
I’ve looked into using libraries like react-native-pdf, rn-pdf-reader-js and react-native-file-viewer, but it seems they require custom native code, which Expo Go doesn’t support.
Is there a way to show PDF files in Expo Go without ejecting or using native modules?
Ideally, I want to keep the PDF viewer within the app itself (so no external browser or in-app browser please). If anyone has suggestions or alternatives that work within Expo Go, I’d really appreciate it!
2
Answers
One approach is to use a WebView to show the PDF.
The following code provides a way to load PDFs via URLs or base64 encoding. The solution is built with
TypeScript
andfunctional components
, and the styles and functionality are fully customizable.It works entirely within Expo Go, without requiring any custom native modules!
I used the following libraries (all supported in Expo Go):
version ~17.0.1
)version 13.8.6
)And obviously:
version 18.2.0
)version 0.74.5
)version ~51.0.28
)You can achieve this using
react-native-pdf
withexpo-asset
. Follow the steps below:app.json
with the plugins:assets/pdfs/sample.pdf
.