在React Native上打开PDF

时间:2018-09-12 20:43:27

标签: javascript reactjs react-native react-redux

我尝试使用react-native-pdf-view打开pdf文件

我的代码是:

export default class PDFExample extends Component {
constructor(props) {
    super(props);
}

render(){
    return(
        <PDFView ref={(pdf)=>{this.pdfView = pdf;}}
            src={"./Tizi.pdf"}
            onLoadComplete = {(pageCount)=>{
            this.pdfView.setNativeProps({
            zoom: 1.5
                });
            }}
    style={styles.pdf}/>
            )
    }
}

我收到此错误:

Invariant Violation: Native component for "RNPDFView" does not exist

1 个答案:

答案 0 :(得分:0)

问题是您没有链接库。这些步骤通常如下:

1)npm安装THE_PACKAGE-保存

2)本机反应THE_PACKAGE

如果程序包不包含任何问题,则将其链接,否则,您需要手动链接它,或切换到其他解决方案,例如https://www.npmjs.com/package/react-native-view-pdf。在这里您还可以找到描述需要完成的步骤的自述文件。它是通用的,因此您可以申请任何软件包。

相关问题