I have installed react-native-pdf and rn-fetch-blob packages to show pdf file.It work's fine on simulator but for some reason i am getting "Error: open failed: ENOENT (No such file or directory)".
Here is my code below:
import React, { Component } from 'react';
import {
StyleSheet,
Dimensions,
View
} from 'react-native';
import Pdf from 'react-native-pdf';
// Screen that shows the contents of a PDF
export default class OpenPdf extends Component {
static navigationOptions = {
title: 'Product Variants'
};
render() {
const source = require('../assets/Product_Variants_Electric_Connections.pdf');
return (
<View style={{width: '100%', height: '100%'}}>
<Pdf style={styles.pdf}
source={source}
onLoadComplete={(numberOfPages, filePath) => {
alert(`number of pages: ${numberOfPages}`);
}}
onPageChanged={(page, numberOfPages) => {
alert(`current page: ${page}`);
}}
onError={(error) => {
alert(`error`+error);
}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
pdf: {
flex: 1,
width: Dimensions.get('window').width
}
});
I have already went through many links, none of the issue is similar to mine. Kindly please suggest what am I missing.
As suggested by @Hardik Virani above in comment, I have removed local url and did like below:
render() {
const source = {uri:'bundle-assets://Product_Variants_Electric_Connections.pdf', cache: true};
return (
<View style={{width: '100%', height: '100%'}}>
<Pdf style={styles.pdf}
source={source}
/>
</View>
);
And Remember Just put your actual pdf in the android/app/src/main/assets/pdf folder of your project.