React native 在本地项目中从URL查看pdf
我一直在尝试使用react native打开pdf文件,但我尝试的每个库都会生成一个错误。我尝试了下面的代码:React native 在本地项目中从URL查看pdf,react-native,pdf,expo,React Native,Pdf,Expo,我一直在尝试使用react native打开pdf文件,但我尝试的每个库都会生成一个错误。我尝试了下面的代码: import React, { Component } from 'react'; import Pdf from 'react-native-pdf'; class OpenBGReport extends Component { render() { const source = {uri:'http://samples.leanpub.com/thereactnat
import React, { Component } from 'react';
import Pdf from 'react-native-pdf';
class OpenBGReport extends Component {
render() {
const source = {uri:'http://samples.leanpub.com/thereactnativebook-sample.pdf',cache:true};
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: 25,
},
pdf: {
flex:1,
width:Dimensions.get('window').width,
height:Dimensions.get('window').height,
}
});
export default OpenBGReport;
import React,{Component}来自'React';
从“react native Pdf”导入Pdf;
类OpenBGReport扩展了组件{
render(){
常量源={uri:'http://samples.leanpub.com/thereactnativebook-sample.pdf,cache:true};
返回(
{
log(`number of pages:${numberOfPages}`);
}}
onPageChanged={(第页,页数)=>{
log(`current page:${page}`);
}}
onError={(错误)=>{
console.log(错误);
}}
style={styles.pdf}/>
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
justifyContent:“flex start”,
对齐项目:“居中”,
玛金托普:25,
},
pdf:{
弹性:1,
宽度:尺寸。获取('窗口')。宽度,
高度:尺寸。获取(“窗口”)。高度,
}
});
导出默认OpenBGReport;
但是,在安装react native pdf之后,我的项目停止工作并返回:null不是对象(正在评估'rnfetchblob.documentdir')
在react native中打开和显示URL中的pdf的最佳方式是什么
感谢您,Expo不支持安装本机模块,
react native pdf
是本机模块。可能的解决办法:
react native cli
或eject expo project。您可以在存储库FAQ部分()中找到更详细的答案链接
API,您始终可以在手机浏览器中打开PDF文件我曾考虑使用带有链接的手机浏览器,但它会向用户显示URL。我无法显示URL。如果您使用expo,则没有简单的解决方案,除非您想弹出项目:我在弹出expo项目时有一段糟糕的经历。lol。有没有办法使用iFrame之类的东西?我想大多数人在拒绝世博会项目方面都有不好的经历。我不知道是否有其他方法可以解决这个问题,我通常使用react native cli来避免此类问题。您在没有退出Expo的情况下找到答案了吗?