Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native : Download and open pdf file, need to work on IOS and Android

Tags:

react-native

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.

like image 609
Narayana Dvl Avatar asked Jan 27 '17 11:01

Narayana Dvl


People also ask

Does React Native work on both iOS and Android?

React Native combines the best parts of native development with React, a best-in-class JavaScript library for building user interfaces. Use a little—or a lot. You can use React Native today in your existing Android and iOS projects or you can create a whole new app from scratch.

Is React Native compatible with iOS?

React Native supports building apps for iOS, Android, and web from a single code base. It's a more affordable technology than Swift, yet it allows creating high-quality apps.


1 Answers

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>
like image 199
Burak Karasoy Avatar answered Oct 18 '22 02:10

Burak Karasoy