I'm trying to open a PDF from URL in my react native project.
I created a open report file:
import React, { Component } from 'react';
import PDFView from 'react-native-view-pdf';
class OpenBGReport extends Component {
render() {
return (
<PDFView
style={{ flex: 1 }}
onError={(error) => console.log('onError', error)}
onLoad={() => console.log('PDF rendered from url')}
resource="http://www.pdf995.com/samples/pdf.pdf"
resourceType="url"
/>
);
}
}
export default OpenBGReport;
However, I'm getting the error: Invariant Violation: Invariant Violation: requireNativeComponent: "PDFView" was not found in the UIManager.
I already tried to run npm link react-native-pdf-view but still same error.
How can I open a PDF from URL in React Native?
Thanks
This is how you manually link for iOS:
cd ios/ && pod deintegrate
Then add the following to your Podfile
:
pod 'RNPDF', :path => '../node_modules/react-native-view-pdf'
Then run pod install
.
This is how you manually link for Android:
Go to your MainApplication.java
and add the following to the top of the file:
import com.rumax.reactnative.pdfviewer.PDFViewPackage;
Then below it:
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new PDFViewPackage());
return packages;
}
android/settings.gradle
, add: include ':react-native-view-pdf'
project(':react-native-view-pdf').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-view-pdf/android')
In android/app/build.gradle
, add:
implementation project(':react-native-view-pdf')
Please keep in mind you are only doing the above because you said you were on RN 0.59.8, you will not need to do this post-RN 60ish as everything is now autolinked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.