无法在react-native-pdf中打开查看PDF

时间:2019-09-06 10:39:32

标签: react-native react-native-pdf

当前,我们使用react-native-pdf打开从服务器端API返回的pdf,例如https://xxxxxx/xxxx-esb/v1/customer/getSrPdfDownload?partyId=S2444201B&srRef=MmOdI42EZLRNeUG38LyNZHk10lbv8s9-zD3lJxzJz1Tg3tS4gAfKbAxOBk36Qwgn。与下面复制的react-native-pdf给出的代码示例不同,它没有指向带有后缀的pdf文件。在iOS上,pdf无法滚动。知道为什么吗?

export default class PDFExample extends React.Component {
    render() {
        const source = {uri:'http://samples.leanpub.com/thereactnativebook-sample.pdf',cache:true};
        //const source = require('./test.pdf');  // ios only
        //const source = {uri:'bundle-assets://test.pdf'};

        //const source = {uri:'file:///sdcard/test.pdf'};
        //const source = {uri:"data:application/pdf;base64,..."};

1 个答案:

答案 0 :(得分:0)

您应该将Pdf中的视图定义为容器。 pdf应该在此容器内。

  <View style={styles.pdf_container}>
        <Pdf
          style={styles.pdf} ...your props />
  </View>

styles.js

import { Dimensions } from "react-native"
const { width, height } = Dimensions.get("window")

  pdf_container: {
    flex: 1
  },
  pdf: {
    height: height - 100
  }
相关问题