Reputation: 211
Using react native I am trying to download a PDF file (Sample PDF File). After download completes, it should open with 3rd party pdf viewer
Please guide me how to do this in react native.
Upvotes: 5
Views: 21376
Reputation: 1690
1) Download base64 encoded pdf file.
2) Decode base64 encoded file ( I suggest you use react-native filehandler)
3)In order to view pdf you can use webview on IOS
<WebView style={{
flex: 1
}} scalesPageToFit={true} source={{
uri: --base64EncodedContent--
}}
>
</WebView>
for android you can use react-native pdf view https://github.com/cnjon/react-native-pdf-view
<PDFView
path={this.props.src} //path of pdf file you saved
pageNumber={1}
onLoadComplete = {(pageCount) => {
}}
style={styles.pdf}>
</PDFView>
Upvotes: 4