I can open the link: https://www.orimi.com/pdf-test.pdf, but when I try with the link: http://94.23.154.57:8081/digital-cert/download-file?id=33FB3234-23EC-472B-AB6F-76436DDCFA45&view=1, I cannot open it. I receive an error message: Error: cannot create document: File not in PDF format or corrupted. I suspect that http might be causing the issue, but the PDF link is returned from the server and I cannot change it to https
import Pdf from 'react-native-pdf';
import {
View,
} from 'react-native';
const PDFExample = ({route}) => {
const source = {
uri: 'http://94.23.154.57:8081/digital-cert/download-file?id=33FB3234-23EC-472B-AB6F-76436DDCFA45&view=1',
cache: true,
};
return (
<View style={styles.container}>
<Pdf
trustAllCerts={false}
source={source}
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 pressed: ${uri}`);
}}
style={styles.pdf}
/>
</View>
)
}
2
Answers
PDF plugin won’t open corrupted format PDF, Even I tried downloading and opening
file://
but it did not work for me. Then I usedfile-viewer
We have three options to open PDF in React Native, the first one you have already done, now you can choose the other two
react-native-webview
react-native-file-viewer
If you choose
webview
then check this answer by aytek answerand you can open the pdf using
file viewer
Example:
If you suspect it to be the http vs https you can try this solution to fix that for iOS.
Add the following to your
info.plist
as explained in this answer:https://stackoverflow.com/a/38427829/11729637