react-native-pdf-view
React Native PDF View (cross-platform support)
Breaking change
React native 0.19 changed the ReactProps class which led to problems with updating native view properties (see https://github.com/facebook/react-native/issues/5649). These errors are corrected in react-native-pdf-view version 0.2.0. Use version 0.2.* for react native >=0.19 and for earlier react native versions use version 0.1.3.
Installation
npm i react-native-pdf-view --save
- In
android/setting.gradle
...include ':PDFView'project(':PDFView').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pdf-view/android')
- In
android/app/build.gradle
...dependencies { ... compile project(':PDFView')}
- register module (in MainActivity.java)
On newer versions of React Native (0.18+):
// <--- import
On older versions of React Native:
// <--- import
Usage
First, require it from your app's JavaScript files with:
import PDFView from 'react-native-pdf-view';
Example
'use strict'; ; ; ; { superprops; } { <PDFView ref={thispdfView = pdf;} src="sdcard/pdffile.pdf" onLoadComplete = { thispdfView; } style=stylespdf/> }var styles = StyleSheet;
Configuration
Property | Type | Default | Description | iOS | Android |
---|---|---|---|---|---|
path | string | null | pdf absolute path | ✔ | ✔ |
src | string | null | pdf absolute path(Deprecated ) |
✔ | ✔ |
asset | string | null | the name of a PDF file in the asset folder | ✔ | |
pageNumber | number | 1 | page index | ✔ | ✔ |
zoom | number | 1.0 | zoom scale | ✔ | ✔ |
onLoadComplete | function | null | page load complete,return page count | ✔ | ✔ |