简体   繁体   English

无法在使用react-native-pdf的android应用程序中滚动pdf文件

[英]Unable to scroll pdf file in android app used react-native-pdf

I have used react-native-pdf in my app and we want to scroll that pdf within the app however it is working fine in on ios but in android, it is not scrolling completely scroll up to 4 pages.我在我的应用程序中使用了 react-native-pdf,我们想在应用程序中滚动该 pdf,但它在 ios 上运行良好,但在 android 中,它不会完全滚动,最多滚动 4 页。 there are 20 pages in the pdf. pdf中有20页。 I have used the below code in my app:-我在我的应用程序中使用了以下代码:-

render () {
    const source = require('./../../../assets/assets/pdfs/pdfname.pdf');
    return (
      <View style={styles.container}>
          <Pdf
              source={source}
              onLoadComplete={(numberOfPages,filePath)=>{
                  console.log(`number of pages: ${numberOfPages}`);
              }}
              onPageChanged={(page,numberOfPages)=>{
                  console.log(`current page: ${page}`);
              }}
              onError={(error)=>{
                  console.log(error);
              }}
              style={styles.pdf}/>
      </View>
  )

  }
}

const styles = StyleSheet.create({
  container: {
      flex: 1,
      justifyContent: 'flex-start',
      alignItems: 'center',
      marginTop: 5,
  },
  pdf: {
      flex:1,
      width:Dimensions.get('window').width - 20,
  }
});

render () {
    const source = require('./../../../assets/assets/pdfs/ebook_1.pdf');
    return (
      <View style={styles.container}>
          <Pdf
              source={source}
              onLoadComplete={(numberOfPages,filePath)=>{
                  console.log(`number of pages: ${numberOfPages}`);
              }}
              onPageChanged={(page,numberOfPages)=>{
                  console.log(`current page: ${page}`);
              }}
              onError={(error)=>{
                  console.log(error);
              }}
              style={styles.pdf}/>
      </View>
  )

  }
}

const styles = StyleSheet.create({
  container: {
      flex: 1,
      justifyContent: 'flex-start',
      alignItems: 'center',
      marginTop: 5,
  },
  pdf: {
      flex:1,
      width:Dimensions.get('window').width - 20,
  }
});

I expect that my pdf scroll completely within the app.我希望我的 pdf 完全在应用程序内滚动。

try wrapping the in ScrollView, worked for me.尝试包装在 ScrollView 中,对我有用。

<View style={styles.container}>
    <ScrollView contentContainerStyle={{ flex: 1 }}>
        <Pdf
            source={source}
            onLoadComplete={()=>{
                console.log(`number of pages: ${numberOfPages}`);
            }}
            onPageChanged={()=>{
                console.log(`current page: ${page}`);
            }}
            onError={(error)=>{
                console.log(error);
            }}
            style={styles.pdf}/>
    </ScrollView>
</View>

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'flex-start',
        alignItems: 'center',
        marginTop: 5
    },
    pdf: {
        flex:1,
        width:Dimensions.get('window').width - 20
    }
});

Try adding some height to your pdf then it works with scroll尝试为您的 pdf 添加一些高度,然后它可以与滚动一起使用

My Styles for pdf我的 pdf 样式

pdfStyles: {
        height: screenHeight - 200,
        width: screenWidth
    },

And this is my pdf这是我的pdf

<Pdf style={Styles.pdfStyles}
                        source={{
                            uri: '/storage/emulated/0/Download/sample.pdf',
                            cache: true
                        }}
                        onLoadComplete={(numberOfPages, filePath) => {
                            console.log(`number of pages: ${numberOfPages}`);
                        }}
                        onPageChanged={(page, numberOfPages) => {
                            console.log(`current page: ${page}`);
                        }}
                        onError={(error) => {
                            console.log(error);
                        }}
                        onPressLink={(uri) => {
                            console.log(`Link presse: ${uri}`)
                        }}
                    />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM