react-native-pdf 6.2.2 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PdfManager.js +6 -11
- package/PinchZoomView.js +1 -1
- package/README.md +120 -94
- package/android/.gradle/5.6.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/5.6.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/5.6.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +3 -3
- package/android/src/main/java/org/wonday/pdf/PdfView.java +21 -2
- package/index.d.ts +13 -3
- package/index.js +25 -37
- package/index.js.flow +3 -3
- package/ios/RCTPdf/RCTPdfView.h +2 -0
- package/ios/RCTPdf/RCTPdfView.m +111 -94
- package/ios/RCTPdf/RCTPdfViewManager.m +1 -1
- package/ios/RCTPdf.xcodeproj/xcuserdata/wonday.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/package.json +21 -6
- package/windows/RCTPdf/PropertySheet.props +16 -0
- package/windows/RCTPdf/RCTPdf.def +3 -0
- package/windows/RCTPdf/RCTPdf.vcxproj +180 -0
- package/windows/RCTPdf/RCTPdf.vcxproj.filters +38 -0
- package/windows/RCTPdf/RCTPdfControl.cpp +667 -0
- package/windows/RCTPdf/RCTPdfControl.h +119 -0
- package/windows/RCTPdf/RCTPdfControl.idl +10 -0
- package/windows/RCTPdf/RCTPdfControl.xaml +33 -0
- package/windows/RCTPdf/RCTPdfViewManager.cpp +69 -0
- package/windows/RCTPdf/RCTPdfViewManager.h +51 -0
- package/windows/RCTPdf/ReactPackageProvider.cpp +15 -0
- package/windows/RCTPdf/ReactPackageProvider.h +16 -0
- package/windows/RCTPdf/ReactPackageProvider.idl +9 -0
- package/windows/RCTPdf/packages.config +4 -0
- package/windows/RCTPdf/pch.cpp +1 -0
- package/windows/RCTPdf/pch.h +29 -0
- package/windows/README.md +21 -0
- package/.babelrc +0 -3
- package/example/.eslintrc.js +0 -4
- package/example/PDFExample.js +0 -176
- package/example/android/app/BUCK +0 -55
- package/example/android/app/build.gradle +0 -210
- package/example/android/app/build_defs.bzl +0 -19
- package/example/android/app/proguard-rules.pro +0 -10
- package/example/android/app/src/debug/AndroidManifest.xml +0 -8
- package/example/android/app/src/main/AndroidManifest.xml +0 -26
- package/example/android/app/src/main/assets/test.pdf +0 -0
- package/example/android/app/src/main/java/com/pdfexample/MainActivity.java +0 -15
- package/example/android/app/src/main/java/com/pdfexample/MainApplication.java +0 -49
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/values/strings.xml +0 -3
- package/example/android/app/src/main/res/values/styles.xml +0 -9
- package/example/android/build.gradle +0 -38
- package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/example/android/gradle.properties +0 -21
- package/example/android/gradlew +0 -188
- package/example/android/gradlew.bat +0 -100
- package/example/android/settings.gradle +0 -3
- package/example/app.json +0 -4
- package/example/babel.config.js +0 -3
- package/example/index.js +0 -9
- package/example/ios/PDFExample/AppDelegate.h +0 -15
- package/example/ios/PDFExample/AppDelegate.m +0 -42
- package/example/ios/PDFExample/Base.lproj/LaunchScreen.xib +0 -42
- package/example/ios/PDFExample/Images.xcassets/AppIcon.appiconset/Contents.json +0 -38
- package/example/ios/PDFExample/Images.xcassets/Contents.json +0 -6
- package/example/ios/PDFExample/Info.plist +0 -57
- package/example/ios/PDFExample/main.m +0 -16
- package/example/ios/PDFExample-tvOS/Info.plist +0 -53
- package/example/ios/PDFExample-tvOSTests/Info.plist +0 -24
- package/example/ios/PDFExample.xcodeproj/project.pbxproj +0 -923
- package/example/ios/PDFExample.xcodeproj/xcshareddata/xcschemes/PDFExample-tvOS.xcscheme +0 -129
- package/example/ios/PDFExample.xcodeproj/xcshareddata/xcschemes/PDFExample.xcscheme +0 -129
- package/example/ios/PDFExample.xcworkspace/contents.xcworkspacedata +0 -10
- package/example/ios/PDFExampleTests/Info.plist +0 -24
- package/example/ios/PDFExampleTests/PDFExampleTests.m +0 -68
- package/example/ios/Podfile +0 -47
- package/example/ios/Podfile.lock +0 -205
- package/example/metro.config.js +0 -17
- package/example/package.json +0 -42
- package/example/test.pdf +0 -0
- package/issue_template.md +0 -13
package/PdfManager.js
CHANGED
|
@@ -7,25 +7,20 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
10
|
-
const invariant = require('fbjs/lib/invariant');
|
|
11
|
-
const PdfManagerNative = require('react-native').NativeModules.PdfManager;
|
|
12
10
|
|
|
11
|
+
const PdfManagerNative = require('react-native').NativeModules.PdfManager;
|
|
13
12
|
|
|
14
13
|
export default class PdfManager {
|
|
15
14
|
|
|
16
|
-
static loadFile(path
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
typeof path === 'string',
|
|
21
|
-
'path must be a valid string.',
|
|
22
|
-
);
|
|
15
|
+
static loadFile(path, password) {
|
|
16
|
+
if (typeof path !== 'string') {
|
|
17
|
+
throw new TypeError('path must be a valid string.');
|
|
18
|
+
}
|
|
23
19
|
|
|
24
20
|
if (password === undefined) {
|
|
25
21
|
password = "";
|
|
26
22
|
}
|
|
27
23
|
|
|
28
24
|
return PdfManagerNative.loadFile(path, password);
|
|
29
|
-
|
|
30
25
|
}
|
|
31
|
-
}
|
|
26
|
+
}
|
package/PinchZoomView.js
CHANGED
|
@@ -108,7 +108,7 @@ export default class PinchZoomView extends Component {
|
|
|
108
108
|
return (
|
|
109
109
|
<View
|
|
110
110
|
{...this.props}
|
|
111
|
-
{...this.gestureHandlers
|
|
111
|
+
{...this.gestureHandlers?.panHandlers}
|
|
112
112
|
style={[styles.container, this.props.style]}>
|
|
113
113
|
{this.props.children}
|
|
114
114
|
</View>
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ A react native PDF view component (cross-platform support)
|
|
|
5
5
|
|
|
6
6
|
### Feature
|
|
7
7
|
|
|
8
|
-
* read a PDF from url
|
|
8
|
+
* read a PDF from url, blob, local file or asset and can cache it.
|
|
9
9
|
* display horizontally or vertically
|
|
10
10
|
* drag and zoom
|
|
11
11
|
* double tap for zoom
|
|
@@ -13,26 +13,27 @@ A react native PDF view component (cross-platform support)
|
|
|
13
13
|
* jump to a specific page in the pdf
|
|
14
14
|
|
|
15
15
|
### Supported versions
|
|
16
|
-
We use [`
|
|
17
|
-
So you should install react-native-pdf and
|
|
16
|
+
We use [`react-native-blob-util`](https://github.com/RonRadtke/react-native-blob-util) to handle file system access in this package,
|
|
17
|
+
So you should install react-native-pdf and react-native-blob-util
|
|
18
18
|
|
|
19
|
-
> The table below shows the supported versions of React Native and
|
|
19
|
+
> The table below shows the supported versions of React Native and react-native-blob-util for different versions of `react-native-pdf`.
|
|
20
20
|
|
|
21
|
-
| React Native | 0.4x - 0.56 | 0.57 | 0.60+ | 0.62+ |
|
|
22
|
-
| ------------------------- | --------------- | ------- | -------- | -------- |
|
|
23
|
-
| react-native-pdf | 4.x.x - 5.0.x | 5.0.9+ | 6.0.0+ | 6.2.0+ |
|
|
24
|
-
|
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
| React Native | 0.4x - 0.56 | 0.57 | 0.60+ | 0.62+ | 0.62+ |
|
|
22
|
+
| ------------------------- | --------------- | ------- | -------- | -------- | -------- |
|
|
23
|
+
| react-native-pdf | 4.x.x - 5.0.x | 5.0.9+ | 6.0.0+ | 6.2.0+ | 6.4.0+ |
|
|
24
|
+
| react-native-blob-util | | | | | 0.13.7+ |
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
> 🚨 Expo: This package is not available in the [Expo Go](https://expo.dev/client) app. Learn how you can use this package in [Custom Dev Clients](https://docs.expo.dev/development/getting-started/) via the out-of-tree [Expo Config Plugin](https://github.com/expo/config-plugins/tree/master/packages/react-native-pdf). Example: [`with-pdf`](https://github.com/expo/examples/tree/master/with-pdf).
|
|
27
28
|
|
|
28
29
|
### Installation
|
|
29
30
|
|
|
30
31
|
```bash
|
|
31
32
|
# Using npm
|
|
32
|
-
npm install react-native-pdf
|
|
33
|
+
npm install react-native-pdf react-native-blob-util --save
|
|
33
34
|
|
|
34
35
|
# or using yarn:
|
|
35
|
-
yarn add react-native-pdf
|
|
36
|
+
yarn add react-native-pdf react-native-blob-util
|
|
36
37
|
```
|
|
37
38
|
|
|
38
39
|
Then follow the instructions for your platform to link react-native-pdf into your project:
|
|
@@ -48,9 +49,7 @@ Run `pod install` in the `ios` directory. Linking is not required in React Nativ
|
|
|
48
49
|
**React Native 0.59 and below**
|
|
49
50
|
|
|
50
51
|
```bash
|
|
51
|
-
react-native link
|
|
52
|
-
react-native link @react-native-community/progress-bar-android
|
|
53
|
-
react-native link @react-native-community/progress-view
|
|
52
|
+
react-native link react-native-blob-util
|
|
54
53
|
react-native link react-native-pdf
|
|
55
54
|
```
|
|
56
55
|
</details>
|
|
@@ -77,15 +76,40 @@ android {
|
|
|
77
76
|
|
|
78
77
|
**React Native 0.59.0 and below**
|
|
79
78
|
```bash
|
|
80
|
-
react-native link
|
|
81
|
-
react-native link @react-native-community/progress-bar-android
|
|
82
|
-
react-native link @react-native-community/progress-view
|
|
79
|
+
react-native link react-native-blob-util
|
|
83
80
|
react-native link react-native-pdf
|
|
84
81
|
```
|
|
85
82
|
|
|
86
83
|
|
|
87
84
|
</details>
|
|
88
85
|
|
|
86
|
+
### Windows installation
|
|
87
|
+
<details>
|
|
88
|
+
<sumary>Windows details</summary>
|
|
89
|
+
|
|
90
|
+
- Open your solution in Visual Studio 2019 (eg. `windows\yourapp.sln`)
|
|
91
|
+
- Right-click Solution icon in Solution Explorer > Add > Existing Project...
|
|
92
|
+
- If running RNW 0.62: add `node_modules\react-native-pdf\windows\RCTPdf\RCTPdf.vcxproj`
|
|
93
|
+
- If running RNW 0.62: add `node_modules\react-native-blob-util\windows\ReactNativeBlobUtil\ReactNativeBlobUtil.vcxproj`
|
|
94
|
+
- Right-click main application project > Add > Reference...
|
|
95
|
+
- Select `progress-view` and in Solution Projects
|
|
96
|
+
- If running 0.62, also select `RCTPdf` and `ReactNativeBlobUtil`
|
|
97
|
+
- In app `pch.h` add `#include "winrt/RCTPdf.h"`
|
|
98
|
+
- If running 0.62, also select `#include "winrt/ReactNativeBlobUtil.h"`
|
|
99
|
+
- In `App.cpp` add `PackageProviders().Append(winrt::progress_view::ReactPackageProvider());` before `InitializeComponent();`
|
|
100
|
+
- If running RNW 0.62, also add `PackageProviders().Append(winrt::RCTPdf::ReactPackageProvider());` and `PackageProviders().Append(winrt::ReactNativeBlobUtil::ReactPackageProvider());`
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
#### Bundling PDFs with the app
|
|
104
|
+
To add a `test.pdf` like in the example add:
|
|
105
|
+
```
|
|
106
|
+
<None Include="..\..\test.pdf">
|
|
107
|
+
<DeploymentContent>true</DeploymentContent>
|
|
108
|
+
</None>
|
|
109
|
+
```
|
|
110
|
+
in the app `.vcxproj` file, before `<None Include="packages.config" />`.
|
|
111
|
+
</details>
|
|
112
|
+
|
|
89
113
|
### FAQ
|
|
90
114
|
<details>
|
|
91
115
|
<summary>FAQ details</summary>
|
|
@@ -145,6 +169,24 @@ react-native run-ios
|
|
|
145
169
|
<details>
|
|
146
170
|
<summary>ChangeLog details</summary>
|
|
147
171
|
|
|
172
|
+
v6.5.0
|
|
173
|
+
1. Fix: replace mavenCentral with maven
|
|
174
|
+
2. Breaking Change(Android): replace deprecated repository: jcenter()
|
|
175
|
+
3. Fix: loading progress
|
|
176
|
+
4. Add: Typed "source" prop
|
|
177
|
+
5. Remove: dependency to fbjs
|
|
178
|
+
|
|
179
|
+
v6.4.0
|
|
180
|
+
1. Remove sample for reducing NPM package size
|
|
181
|
+
2. Add support for setting a filename for the cached pdf file
|
|
182
|
+
3. Use react-native-blob-util instead of rn-fetch-blob
|
|
183
|
+
4. Add blob support
|
|
184
|
+
5. remove progress-view dependency
|
|
185
|
+
|
|
186
|
+
v6.3.0
|
|
187
|
+
1. Add windows support
|
|
188
|
+
2. Fixed some bugs
|
|
189
|
+
|
|
148
190
|
v6.2.2
|
|
149
191
|
1. Fixed incorrect type of onPageSingleTap and onScaleChanged argument
|
|
150
192
|
2. Fixed included missing setPage method in TypeScript and Flow types
|
|
@@ -180,25 +222,6 @@ v6.0.0
|
|
|
180
222
|
1. Add JS callback onPressLink for pdf link press listener
|
|
181
223
|
2. Fix calling setState while unmounted
|
|
182
224
|
|
|
183
|
-
v5.1.7
|
|
184
|
-
1. Downgraded to AndroidPdfViewer 3.1.0-beta.1
|
|
185
|
-
|
|
186
|
-
v5.1.6
|
|
187
|
-
1. Fixed componentWillReceiveProps and componentWillMount warnings
|
|
188
|
-
|
|
189
|
-
v5.1.5
|
|
190
|
-
1. Added setPage() method
|
|
191
|
-
2. Upgraded to AndroidPdfViewer to 3.2.0-beta.1
|
|
192
|
-
3. Fixed some codes ,readme and sample
|
|
193
|
-
|
|
194
|
-
v5.1.4
|
|
195
|
-
1. Updated example project to RN 0.60.4
|
|
196
|
-
2. Fixed blank view after native module got recycled in onDetachedFromWindow event
|
|
197
|
-
3. Restore singleTap, only callback, do not change scale
|
|
198
|
-
|
|
199
|
-
v5.1.3
|
|
200
|
-
1. Removed singleTap action from iOS, make the same with Android.
|
|
201
|
-
|
|
202
225
|
|
|
203
226
|
[[more]](https://github.com/wonday/react-native-pdf/releases)
|
|
204
227
|
|
|
@@ -217,38 +240,38 @@ v5.1.3
|
|
|
217
240
|
|
|
218
241
|
import React from 'react';
|
|
219
242
|
import { StyleSheet, Dimensions, View } from 'react-native';
|
|
220
|
-
|
|
221
243
|
import Pdf from 'react-native-pdf';
|
|
222
244
|
|
|
223
245
|
export default class PDFExample extends React.Component {
|
|
224
246
|
render() {
|
|
225
|
-
const source = {uri:'http://samples.leanpub.com/thereactnativebook-sample.pdf',cache:true};
|
|
247
|
+
const source = { uri: 'http://samples.leanpub.com/thereactnativebook-sample.pdf', cache: true };
|
|
226
248
|
//const source = require('./test.pdf'); // ios only
|
|
227
|
-
//const source = {uri:'bundle-assets://test.pdf'};
|
|
228
|
-
|
|
249
|
+
//const source = {uri:'bundle-assets://test.pdf' };
|
|
229
250
|
//const source = {uri:'file:///sdcard/test.pdf'};
|
|
230
251
|
//const source = {uri:"data:application/pdf;base64,JVBERi0xLjcKJc..."};
|
|
252
|
+
//const source = {uri:"content://com.example.blobs/xxxxxxxx-...?offset=0&size=xxx"};
|
|
253
|
+
//const source = {uri:"blob:xxxxxxxx-...?offset=0&size=xxx"};
|
|
231
254
|
|
|
232
255
|
return (
|
|
233
256
|
<View style={styles.container}>
|
|
234
257
|
<Pdf
|
|
235
258
|
source={source}
|
|
236
|
-
onLoadComplete={(numberOfPages,filePath)=>{
|
|
237
|
-
console.log(`
|
|
259
|
+
onLoadComplete={(numberOfPages,filePath) => {
|
|
260
|
+
console.log(`Number of pages: ${numberOfPages}`);
|
|
238
261
|
}}
|
|
239
|
-
onPageChanged={(page,numberOfPages)=>{
|
|
240
|
-
console.log(`
|
|
262
|
+
onPageChanged={(page,numberOfPages) => {
|
|
263
|
+
console.log(`Current page: ${page}`);
|
|
241
264
|
}}
|
|
242
|
-
onError={(error)=>{
|
|
265
|
+
onError={(error) => {
|
|
243
266
|
console.log(error);
|
|
244
267
|
}}
|
|
245
|
-
onPressLink={(uri)=>{
|
|
246
|
-
console.log(`Link
|
|
268
|
+
onPressLink={(uri) => {
|
|
269
|
+
console.log(`Link pressed: ${uri}`);
|
|
247
270
|
}}
|
|
248
271
|
style={styles.pdf}/>
|
|
249
272
|
</View>
|
|
250
273
|
)
|
|
251
|
-
|
|
274
|
+
}
|
|
252
275
|
}
|
|
253
276
|
|
|
254
277
|
const styles = StyleSheet.create({
|
|
@@ -270,57 +293,60 @@ const styles = StyleSheet.create({
|
|
|
270
293
|
|
|
271
294
|
### Configuration
|
|
272
295
|
|
|
273
|
-
| Property | Type | Default | Description | iOS | Android | FirstRelease |
|
|
274
|
-
| ------------- |:-------------:|:----------------:| ------------------- | ------| ------- | ------------ |
|
|
275
|
-
| source | object | not null | PDF source like {uri:xxx, cache:false}. see the following for detail.| ✔ | ✔ | <3.0 |
|
|
276
|
-
| page | number | 1 | initial page index | ✔ | ✔ | <3.0 |
|
|
277
|
-
| scale | number | 1.0 | should minScale<=scale<=maxScale| ✔ | ✔ | <3.0 |
|
|
278
|
-
| minScale | number | 1.0 | min scale| ✔ | ✔ | 5.0.5 |
|
|
279
|
-
| maxScale | number | 3.0 | max scale| ✔ | ✔ | 5.0.5 |
|
|
280
|
-
| horizontal | bool | false | draw page direction, if you want to listen the orientation change, you can use [[react-native-orientation-locker]](https://github.com/wonday/react-native-orientation-locker)| ✔ | ✔ | <3.0 |
|
|
281
|
-
| fitWidth | bool | false | if true fit the width of view, can not use fitWidth=true together with scale| ✔ | ✔ | <3.0, abandoned from 3.0 |
|
|
282
|
-
| fitPolicy | number | 2 | 0:fit width, 1:fit height, 2:fit both(default)| ✔ | ✔ | 3.0 |
|
|
283
|
-
| spacing | number | 10 | the breaker size between pages| ✔ | ✔ | <3.0 |
|
|
284
|
-
| password | string | "" | pdf password, if password error, will call OnError() with message "Password required or incorrect password." | ✔ | ✔ | <3.0 |
|
|
285
|
-
| style | object | {backgroundColor:"#eee"} | support normal view style, you can use this to set border/spacing color... | ✔ | ✔ | <3.0 |
|
|
286
|
-
|
|
|
287
|
-
|
|
|
288
|
-
|
|
|
289
|
-
|
|
|
290
|
-
|
|
|
291
|
-
|
|
|
292
|
-
|
|
|
293
|
-
|
|
|
294
|
-
|
|
|
295
|
-
|
|
|
296
|
-
|
|
|
297
|
-
|
|
|
298
|
-
|
|
|
299
|
-
|
|
|
300
|
-
| onPressLink | function(uri) | null | callback when link tapped | ✔ | ✔ | 6.0.0 |
|
|
296
|
+
| Property | Type | Default | Description | iOS | Android | Windows | FirstRelease |
|
|
297
|
+
| ------------- |:-------------:|:----------------:| ------------------- | ------| ------- | ------- | ------------ |
|
|
298
|
+
| source | object | not null | PDF source like {uri:xxx, cache:false}. see the following for detail.| ✔ | ✔ | ✔ | <3.0 |
|
|
299
|
+
| page | number | 1 | initial page index | ✔ | ✔ | ✔ | <3.0 |
|
|
300
|
+
| scale | number | 1.0 | should minScale<=scale<=maxScale| ✔ | ✔ | ✔ | <3.0 |
|
|
301
|
+
| minScale | number | 1.0 | min scale| ✔ | ✔ | ✔ | 5.0.5 |
|
|
302
|
+
| maxScale | number | 3.0 | max scale| ✔ | ✔ | ✔ | 5.0.5 |
|
|
303
|
+
| horizontal | bool | false | draw page direction, if you want to listen the orientation change, you can use [[react-native-orientation-locker]](https://github.com/wonday/react-native-orientation-locker)| ✔ | ✔ | ✔ | <3.0 |
|
|
304
|
+
| fitWidth | bool | false | if true fit the width of view, can not use fitWidth=true together with scale| ✔ | ✔ | ✔ | <3.0, abandoned from 3.0 |
|
|
305
|
+
| fitPolicy | number | 2 | 0:fit width, 1:fit height, 2:fit both(default)| ✔ | ✔ | ✔ | 3.0 |
|
|
306
|
+
| spacing | number | 10 | the breaker size between pages| ✔ | ✔ | ✔ | <3.0 |
|
|
307
|
+
| password | string | "" | pdf password, if password error, will call OnError() with message "Password required or incorrect password." | ✔ | ✔ | ✔ | <3.0 |
|
|
308
|
+
| style | object | {backgroundColor:"#eee"} | support normal view style, you can use this to set border/spacing color... | ✔ | ✔ | ✔ | <3.0 |
|
|
309
|
+
| renderActivityIndicator | (progress) => Component | <ProgressBar/> | when loading show it as an indicator, you can use your component| ✔ | ✔ | ✖ | <3.0 |
|
|
310
|
+
| enableAntialiasing | bool | true | improve rendering a little bit on low-res screens, but maybe course some problem on Android 4.4, so add a switch | ✖ | ✔ | ✖ | <3.0 |
|
|
311
|
+
| enablePaging | bool | false | only show one page in screen | ✔ | ✔ | ✔ | 5.0.1 |
|
|
312
|
+
| enableRTL | bool | false | scroll page as "page3, page2, page1" | ✔ | ✖ | ✔ | 5.0.1 |
|
|
313
|
+
| enableAnnotationRendering | bool | true | enable rendering annotation, notice:iOS only support initial setting,not support realtime changing | ✔ | ✔ | ✖ | 5.0.3 |
|
|
314
|
+
| trustAllCerts | bool | true | Allow connections to servers with self-signed certification | ✔ | ✔ | ✖ | 6.0.? |
|
|
315
|
+
| singlePage | bool | false | Only show first page, useful for thumbnail views | ✔ | ✔ | ✔ | 6.2.1 |
|
|
316
|
+
| onLoadProgress | function(percent) | null | callback when loading, return loading progress (0-1) | ✔ | ✔ | ✖ | <3.0 |
|
|
317
|
+
| onLoadComplete | function(numberOfPages, path, {width, height}, tableContents) | null | callback when pdf load completed, return total page count, pdf local/cache path, {width,height} and table of contents | ✔ | ✔ | ✔ but without tableContents | <3.0 |
|
|
318
|
+
| onPageChanged | function(page,numberOfPages) | null | callback when page changed ,return current page and total page count | ✔ | ✔ | ✔ | <3.0 |
|
|
319
|
+
| onError | function(error) | null | callback when error happened | ✔ | ✔ | ✔ | <3.0 |
|
|
320
|
+
| onPageSingleTap | function(page) | null | callback when page was single tapped | ✔ | ✔ | ✔ | 3.0 |
|
|
321
|
+
| onScaleChanged | function(scale) | null | callback when scale page | ✔ | ✔ | ✔ | 3.0 |
|
|
322
|
+
| onPressLink | function(uri) | null | callback when link tapped | ✔ | ✔ | ✖ | 6.0.0 |
|
|
301
323
|
|
|
302
324
|
#### parameters of source
|
|
303
325
|
|
|
304
|
-
| parameter | Description | default | iOS | Android |
|
|
305
|
-
| ------------ | ----------- | ------- | --- | ------- |
|
|
306
|
-
| uri | pdf source, see the forllowing for detail.| required | ✔ | ✔ |
|
|
307
|
-
| cache | use cache or not | false | ✔ | ✔ |
|
|
308
|
-
|
|
|
309
|
-
|
|
|
310
|
-
|
|
|
326
|
+
| parameter | Description | default | iOS | Android | Windows |
|
|
327
|
+
| ------------ | ----------- | ------- | --- | ------- | ------- |
|
|
328
|
+
| uri | pdf source, see the forllowing for detail.| required | ✔ | ✔ | ✔ |
|
|
329
|
+
| cache | use cache or not | false | ✔ | ✔ | ✖ |
|
|
330
|
+
| cacheFileName | specific file name for cached pdf file | SHA1(uri) result | ✔ | ✔ | ✖ |
|
|
331
|
+
| expiration | cache file expired seconds (0 is not expired) | 0 | ✔ | ✔ | ✖ |
|
|
332
|
+
| method | request method when uri is a url | "GET" | ✔ | ✔ | ✖ |
|
|
333
|
+
| headers | request headers when uri is a url | {} | ✔ | ✔ | ✖ |
|
|
311
334
|
|
|
312
335
|
#### types of source.uri
|
|
313
336
|
|
|
314
|
-
| Usage
|
|
315
|
-
| ------------ | ----------- | --- | ------- |
|
|
316
|
-
| `{uri:"http://xxx/xxx.pdf"}` | load pdf from a url | ✔ | ✔ |
|
|
317
|
-
| `{require("./test.pdf")}` | load pdf relate to js file (do not need add by xcode) | ✔ | ✖ |
|
|
318
|
-
| `{uri:"bundle-assets://path/to/xxx.pdf"}` | load pdf from assets, the file should be at android/app/src/main/assets/path/to/xxx.pdf | ✖ | ✔ |
|
|
319
|
-
| `{uri:"bundle-assets://xxx.pdf"}` | load pdf from assets, you must add pdf to project by xcode. this does not support folder. | ✔ | ✖ |
|
|
320
|
-
| `{uri:"data:application/pdf;base64,JVBERi0xLjcKJc..."}` | load pdf from base64 string | ✔ | ✔ |
|
|
321
|
-
| `{uri:"file:///absolute/path/to/xxx.pdf"}` | load pdf from local file system | ✔
|
|
322
|
-
|
|
323
|
-
|
|
337
|
+
| Usage | Description | iOS | Android | Windows |
|
|
338
|
+
| ------------ | ----------- | --- | ------- | ------- |
|
|
339
|
+
| `{uri:"http://xxx/xxx.pdf"}` | load pdf from a url | ✔ | ✔ | ✔ |
|
|
340
|
+
| `{require("./test.pdf")}` | load pdf relate to js file (do not need add by xcode) | ✔ | ✖ | ✖ |
|
|
341
|
+
| `{uri:"bundle-assets://path/to/xxx.pdf"}` | load pdf from assets, the file should be at android/app/src/main/assets/path/to/xxx.pdf | ✖ | ✔ | ✖ |
|
|
342
|
+
| `{uri:"bundle-assets://xxx.pdf"}` | load pdf from assets, you must add pdf to project by xcode. this does not support folder. | ✔ | ✖ | ✖ |
|
|
343
|
+
| `{uri:"data:application/pdf;base64,JVBERi0xLjcKJc..."}` | load pdf from base64 string | ✔ | ✔ | ✔ |
|
|
344
|
+
| `{uri:"file:///absolute/path/to/xxx.pdf"}` | load pdf from local file system | ✔ | ✔ | ✔ |
|
|
345
|
+
| `{uri:"ms-appx:///xxx.pdf"}}` | load pdf bundled with UWP app | ✖ | ✖ | ✔ |
|
|
346
|
+
| `{uri:"content://com.example.blobs/xxxxxxxx-...?offset=0&size=xxx"}` | load pdf from content URI | ✔* | ✖ | ✖ |
|
|
347
|
+
| `{uri:"blob:xxxxxxxx-...?offset=0&size=xxx"}` | load pdf from blob URL | ✖ | ✔ | ✖ |
|
|
348
|
+
|
|
349
|
+
\*) requires building React Native from source with [this patch](https://github.com/facebook/react-native/pull/31789)
|
|
324
350
|
### Methods
|
|
325
351
|
* [setPage](#setPage)
|
|
326
352
|
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
File without changes
|
package/android/build.gradle
CHANGED
|
@@ -2,7 +2,7 @@ description = 'react-native-pdf'
|
|
|
2
2
|
|
|
3
3
|
buildscript {
|
|
4
4
|
repositories {
|
|
5
|
-
|
|
5
|
+
mavenCentral()
|
|
6
6
|
google()
|
|
7
7
|
}
|
|
8
8
|
|
|
@@ -12,11 +12,11 @@ buildscript {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
repositories {
|
|
15
|
-
|
|
15
|
+
mavenCentral()
|
|
16
16
|
maven {
|
|
17
17
|
url 'https://jitpack.io'
|
|
18
18
|
content {
|
|
19
|
-
// Use Jitpack only for AndroidPdfViewer; the rest is hosted at
|
|
19
|
+
// Use Jitpack only for AndroidPdfViewer; the rest is hosted at mavenCentral.
|
|
20
20
|
includeGroup "com.github.TalbotGooday"
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -10,6 +10,7 @@ package org.wonday.pdf;
|
|
|
10
10
|
|
|
11
11
|
import java.io.File;
|
|
12
12
|
|
|
13
|
+
import android.content.ContentResolver;
|
|
13
14
|
import android.content.Context;
|
|
14
15
|
import android.view.View;
|
|
15
16
|
import android.view.ViewGroup;
|
|
@@ -49,6 +50,9 @@ import com.facebook.common.logging.FLog;
|
|
|
49
50
|
import com.facebook.react.common.ReactConstants;
|
|
50
51
|
|
|
51
52
|
import static java.lang.String.format;
|
|
53
|
+
|
|
54
|
+
import java.io.FileNotFoundException;
|
|
55
|
+
import java.io.InputStream;
|
|
52
56
|
import java.lang.ClassCastException;
|
|
53
57
|
|
|
54
58
|
import com.shockwave.pdfium.PdfDocument;
|
|
@@ -222,8 +226,23 @@ public class PdfView extends PDFView implements OnPageChangeListener,OnLoadCompl
|
|
|
222
226
|
Constants.Pinch.MINIMUM_ZOOM = this.minScale;
|
|
223
227
|
Constants.Pinch.MAXIMUM_ZOOM = this.maxScale;
|
|
224
228
|
|
|
225
|
-
Configurator configurator
|
|
226
|
-
|
|
229
|
+
Configurator configurator;
|
|
230
|
+
|
|
231
|
+
if (this.path.startsWith("content://")) {
|
|
232
|
+
ContentResolver contentResolver = getContext().getContentResolver();
|
|
233
|
+
InputStream inputStream = null;
|
|
234
|
+
Uri uri = Uri.parse(this.path);
|
|
235
|
+
try {
|
|
236
|
+
inputStream = contentResolver.openInputStream(uri);
|
|
237
|
+
} catch (FileNotFoundException e) {
|
|
238
|
+
throw new RuntimeException(e.getMessage());
|
|
239
|
+
}
|
|
240
|
+
configurator = this.fromStream(inputStream);
|
|
241
|
+
} else {
|
|
242
|
+
configurator = this.fromUri(getURI(this.path));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
configurator.defaultPage(this.page-1)
|
|
227
246
|
.swipeHorizontal(this.horizontal)
|
|
228
247
|
.onPageChange(this)
|
|
229
248
|
.onLoad(this)
|
package/index.d.ts
CHANGED
|
@@ -16,9 +16,20 @@ export type TableContent = {
|
|
|
16
16
|
title: string,
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
export type Source = {
|
|
20
|
+
uri?: string;
|
|
21
|
+
headers?: {
|
|
22
|
+
[key: string]: string;
|
|
23
|
+
};
|
|
24
|
+
cache?: boolean;
|
|
25
|
+
cacheFileName?: string;
|
|
26
|
+
expiration?: number;
|
|
27
|
+
method?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
19
30
|
interface Props {
|
|
20
31
|
style?: ReactNative.StyleProp<ReactNative.ViewStyle>,
|
|
21
|
-
source:
|
|
32
|
+
source: Source | number,
|
|
22
33
|
page?: number,
|
|
23
34
|
scale?: number,
|
|
24
35
|
minScale?: number,
|
|
@@ -26,8 +37,7 @@ interface Props {
|
|
|
26
37
|
horizontal?: boolean,
|
|
27
38
|
spacing?: number,
|
|
28
39
|
password?: string,
|
|
29
|
-
|
|
30
|
-
activityIndicatorProps?: object,
|
|
40
|
+
renderActivityIndicator?: (progress: number) => React.ReactElement,
|
|
31
41
|
enableAntialiasing?: boolean,
|
|
32
42
|
enablePaging?: boolean,
|
|
33
43
|
enableRTL?: boolean,
|
package/index.js
CHANGED
|
@@ -15,13 +15,11 @@ import {
|
|
|
15
15
|
Platform,
|
|
16
16
|
ViewPropTypes,
|
|
17
17
|
StyleSheet,
|
|
18
|
-
Image
|
|
18
|
+
Image,
|
|
19
|
+
Text
|
|
19
20
|
} from 'react-native';
|
|
20
21
|
|
|
21
|
-
import
|
|
22
|
-
import { ProgressView } from '@react-native-community/progress-view'
|
|
23
|
-
|
|
24
|
-
import RNFetchBlob from 'rn-fetch-blob';
|
|
22
|
+
import ReactNativeBlobUtil from 'react-native-blob-util'
|
|
25
23
|
|
|
26
24
|
const SHA1 = require('crypto-js/sha1');
|
|
27
25
|
import PdfView from './PdfView';
|
|
@@ -34,6 +32,7 @@ export default class Pdf extends Component {
|
|
|
34
32
|
PropTypes.shape({
|
|
35
33
|
uri: PropTypes.string,
|
|
36
34
|
cache: PropTypes.bool,
|
|
35
|
+
cacheFileName: PropTypes.string,
|
|
37
36
|
expiration: PropTypes.number,
|
|
38
37
|
}),
|
|
39
38
|
// Opaque type returned by require('./test.pdf')
|
|
@@ -46,9 +45,7 @@ export default class Pdf extends Component {
|
|
|
46
45
|
horizontal: PropTypes.bool,
|
|
47
46
|
spacing: PropTypes.number,
|
|
48
47
|
password: PropTypes.string,
|
|
49
|
-
|
|
50
|
-
activityIndicator: PropTypes.any,
|
|
51
|
-
activityIndicatorProps: PropTypes.any,
|
|
48
|
+
renderActivityIndicator: PropTypes.func,
|
|
52
49
|
enableAntialiasing: PropTypes.bool,
|
|
53
50
|
enableAnnotationRendering: PropTypes.bool,
|
|
54
51
|
enablePaging: PropTypes.bool,
|
|
@@ -86,7 +83,6 @@ export default class Pdf extends Component {
|
|
|
86
83
|
enableAnnotationRendering: true,
|
|
87
84
|
enablePaging: false,
|
|
88
85
|
enableRTL: false,
|
|
89
|
-
activityIndicatorProps: {color: '#009900', progressTintColor: '#009900'},
|
|
90
86
|
trustAllCerts: true,
|
|
91
87
|
usePDFKit: true,
|
|
92
88
|
singlePage: false,
|
|
@@ -166,16 +162,15 @@ export default class Pdf extends Component {
|
|
|
166
162
|
const source = Image.resolveAssetSource(newSource) || {};
|
|
167
163
|
|
|
168
164
|
let uri = source.uri || '';
|
|
169
|
-
|
|
170
165
|
// first set to initial state
|
|
171
166
|
if (this._mounted) {
|
|
172
167
|
this.setState({isDownloaded: false, path: '', progress: 0});
|
|
173
168
|
}
|
|
174
|
-
|
|
175
|
-
const cacheFile =
|
|
169
|
+
const filename = source.cacheFileName || SHA1(uri) + '.pdf';
|
|
170
|
+
const cacheFile = ReactNativeBlobUtil.fs.dirs.CacheDir + '/' + filename;
|
|
176
171
|
|
|
177
172
|
if (source.cache) {
|
|
178
|
-
|
|
173
|
+
ReactNativeBlobUtil.fs
|
|
179
174
|
.stat(cacheFile)
|
|
180
175
|
.then(stats => {
|
|
181
176
|
if (!Boolean(source.expiration) || (source.expiration * 1000 + stats.lastModified) > (new Date().getTime())) {
|
|
@@ -206,7 +201,8 @@ export default class Pdf extends Component {
|
|
|
206
201
|
const isAsset = !!(uri && uri.match(/^bundle-assets:\/\//));
|
|
207
202
|
const isBase64 = !!(uri && uri.match(/^data:application\/pdf;base64/));
|
|
208
203
|
|
|
209
|
-
const
|
|
204
|
+
const filename = source.cacheFileName || SHA1(uri) + '.pdf';
|
|
205
|
+
const cacheFile = ReactNativeBlobUtil.fs.dirs.CacheDir + '/' + filename;
|
|
210
206
|
|
|
211
207
|
// delete old cache file
|
|
212
208
|
this._unlinkFile(cacheFile);
|
|
@@ -214,7 +210,7 @@ export default class Pdf extends Component {
|
|
|
214
210
|
if (isNetwork) {
|
|
215
211
|
this._downloadFile(source, cacheFile);
|
|
216
212
|
} else if (isAsset) {
|
|
217
|
-
|
|
213
|
+
ReactNativeBlobUtil.fs
|
|
218
214
|
.cp(uri, cacheFile)
|
|
219
215
|
.then(() => {
|
|
220
216
|
if (this._mounted) {
|
|
@@ -227,7 +223,7 @@ export default class Pdf extends Component {
|
|
|
227
223
|
})
|
|
228
224
|
} else if (isBase64) {
|
|
229
225
|
let data = uri.replace(/data:application\/pdf;base64,/i, '');
|
|
230
|
-
|
|
226
|
+
ReactNativeBlobUtil.fs
|
|
231
227
|
.writeFile(cacheFile, data, 'base64')
|
|
232
228
|
.then(() => {
|
|
233
229
|
if (this._mounted) {
|
|
@@ -267,7 +263,7 @@ export default class Pdf extends Component {
|
|
|
267
263
|
const tempCacheFile = cacheFile + '.tmp';
|
|
268
264
|
this._unlinkFile(tempCacheFile);
|
|
269
265
|
|
|
270
|
-
this.lastRNBFTask =
|
|
266
|
+
this.lastRNBFTask = ReactNativeBlobUtil.config({
|
|
271
267
|
// response data will be saved to this path if it has access right.
|
|
272
268
|
path: tempCacheFile,
|
|
273
269
|
trusty: this.props.trustAllCerts,
|
|
@@ -296,7 +292,7 @@ export default class Pdf extends Component {
|
|
|
296
292
|
let actualContentLength;
|
|
297
293
|
|
|
298
294
|
try {
|
|
299
|
-
const fileStats = await
|
|
295
|
+
const fileStats = await ReactNativeBlobUtil.fs.stat(res.path());
|
|
300
296
|
|
|
301
297
|
if (!fileStats || !fileStats.size) {
|
|
302
298
|
throw new Error("FileNotFound:" + source.uri);
|
|
@@ -313,7 +309,7 @@ export default class Pdf extends Component {
|
|
|
313
309
|
}
|
|
314
310
|
|
|
315
311
|
this._unlinkFile(cacheFile);
|
|
316
|
-
|
|
312
|
+
ReactNativeBlobUtil.fs
|
|
317
313
|
.cp(tempCacheFile, cacheFile)
|
|
318
314
|
.then(() => {
|
|
319
315
|
if (this._mounted) {
|
|
@@ -335,7 +331,7 @@ export default class Pdf extends Component {
|
|
|
335
331
|
|
|
336
332
|
_unlinkFile = async (file) => {
|
|
337
333
|
try {
|
|
338
|
-
await
|
|
334
|
+
await ReactNativeBlobUtil.fs.unlink(file);
|
|
339
335
|
} catch (e) {
|
|
340
336
|
|
|
341
337
|
}
|
|
@@ -392,30 +388,18 @@ export default class Pdf extends Component {
|
|
|
392
388
|
};
|
|
393
389
|
|
|
394
390
|
render() {
|
|
395
|
-
if (Platform.OS === "android" || Platform.OS === "ios") {
|
|
391
|
+
if (Platform.OS === "android" || Platform.OS === "ios" || Platform.OS === "windows") {
|
|
396
392
|
return (
|
|
397
393
|
<View style={[this.props.style,{overflow: 'hidden'}]}>
|
|
398
394
|
{!this.state.isDownloaded?
|
|
399
395
|
(<View
|
|
400
396
|
style={styles.progressContainer}
|
|
401
397
|
>
|
|
402
|
-
{this.props.
|
|
403
|
-
? this.props.
|
|
404
|
-
:
|
|
405
|
-
? <ProgressBar
|
|
406
|
-
progress={this.state.progress}
|
|
407
|
-
indeterminate={false}
|
|
408
|
-
styleAttr="Horizontal"
|
|
409
|
-
style={styles.progressBar}
|
|
410
|
-
{...this.props.activityIndicatorProps}
|
|
411
|
-
/>
|
|
412
|
-
: <ProgressView
|
|
413
|
-
progress={this.state.progress}
|
|
414
|
-
style={styles.progressBar}
|
|
415
|
-
{...this.props.activityIndicatorProps}
|
|
416
|
-
/>}
|
|
398
|
+
{this.props.renderActivityIndicator
|
|
399
|
+
? this.props.renderActivityIndicator(this.state.progress)
|
|
400
|
+
: <Text>{`${(this.state.progress * 100).toFixed(2)}%`}</Text>}
|
|
417
401
|
</View>):(
|
|
418
|
-
Platform.OS === "android"?(
|
|
402
|
+
Platform.OS === "android" || Platform.OS === "windows"?(
|
|
419
403
|
<PdfCustom
|
|
420
404
|
ref={component => (this._root = component)}
|
|
421
405
|
{...this.props}
|
|
@@ -463,6 +447,10 @@ if (Platform.OS === "android") {
|
|
|
463
447
|
var PdfCustom = requireNativeComponent('RCTPdfView', Pdf, {
|
|
464
448
|
nativeOnly: {path: true, onChange: true},
|
|
465
449
|
})
|
|
450
|
+
} else if (Platform.OS === "windows") {
|
|
451
|
+
var PdfCustom = requireNativeComponent('RCTPdf', Pdf, {
|
|
452
|
+
nativeOnly: {path: true, onChange: true},
|
|
453
|
+
})
|
|
466
454
|
}
|
|
467
455
|
|
|
468
456
|
|