React Native : 下载并打开pdf文件,需要在IOS和Android上运行 [英] React Native : Download and open pdf file, need to work on IOS and Android

查看:209
本文介绍了React Native : 下载并打开pdf文件,需要在IOS和Android上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 react native 我试图下载一个 PDF 文件 (示例 PDF 文件).下载完成后,它应该用 3rd 方 pdf 查看器打开

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

请指导我如何在 React Native 中做到这一点.

Please guide me how to do this in react native.

推荐答案

1) 下载 base64 编码的 pdf 文件.

1) Download base64 encoded pdf file.

2) 解码 base64 编码的文件(我建议你使用 react-native filehandler)

2) Decode base64 encoded file ( I suggest you use react-native filehandler)

3)为了查看pdf,你可以在IOS上使用webview

3)In order to view pdf you can use webview on IOS

     <WebView style={{
          flex: 1
        }}  scalesPageToFit={true} source={{
          uri: --base64EncodedContent--
        }}
        >
       </WebView>

对于安卓,你可以使用 react-native pdf 视图 https://github.com/cnjon/react-native-pdf-view

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>

这篇关于React Native : 下载并打开pdf文件,需要在IOS和Android上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆