react-native-pdf-renderer 1.3.0 → 1.3.2
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/README.md +23 -11
- package/dist/PdfRendererView.d.ts +2 -1
- package/dist/PdfRendererView.js +2 -2
- package/dist/PdfRendererView.js.map +1 -1
- package/dist/mock.d.ts +4 -0
- package/dist/mock.js +7 -0
- package/dist/mock.js.map +1 -0
- package/ios/ReactNativePdfRendererLibrary/RNPdfRendererModule.m +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,11 +14,11 @@ It uses [PdfRenderer](https://developer.android.com/reference/android/graphics/p
|
|
|
14
14
|
|
|
15
15
|
## Why another PDF renderer?
|
|
16
16
|
|
|
17
|
-
The main reason why I create this library is to avoid using third
|
|
17
|
+
The main reason why I create this library is to avoid using third-party native dependencies, like `com.github.TalbotGooday:AndroidPdfViewer`, `com.github.mhiew:android-pdf-viewer`, `react-native-blob-util` or even `react-native-webview`.
|
|
18
18
|
|
|
19
19
|
But why?
|
|
20
20
|
|
|
21
|
-
Every React Native developer knows (or will discover soon) the pain of updating the React Native ecosystem when a new version of Android or iOS comes out, so here we want to avoid this pain as much as possible.
|
|
21
|
+
Every React Native developer knows (or will discover soon) [the pain of updating the React Native ecosystem](https://x.com/flexbox_/status/1806786055057674337) when a new version of Android or iOS comes out, so here we want to avoid this pain as much as possible.
|
|
22
22
|
|
|
23
23
|
## Requirements
|
|
24
24
|
|
|
@@ -65,32 +65,38 @@ const App = () => {
|
|
|
65
65
|
export default App;
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
The `source` prop must point to a file stored inside device memory.
|
|
68
|
+
The `source` prop must point to a file stored inside the device memory.
|
|
69
69
|
|
|
70
|
-
If the file is online, you can use some third
|
|
70
|
+
If the file is online, you can use some third-party library like `expo-file-system`, `rn-fetch-blob`, or `react-native-blob-util` to download and save it locally.
|
|
71
71
|
|
|
72
72
|
For more details, see the [Sample Project](https://github.com/douglasjunior/react-native-pdf-renderer/blob/main/Sample/App.tsx).
|
|
73
73
|
|
|
74
74
|
## PdfRendererView props
|
|
75
75
|
|
|
76
|
-
|Name|
|
|
76
|
+
|Name|Type|Default|Description|
|
|
77
77
|
|-|-|-|-|
|
|
78
|
-
|source|`string`||Path to a file stored on device.|
|
|
78
|
+
|source|`string`||Path to a file stored on the device.|
|
|
79
79
|
|distanceBetweenPages|`number`|`16`|Distance in `DPI` between pages.|
|
|
80
80
|
|maxZoom|`number`|`5`|Max zoom scale.|
|
|
81
81
|
|singlePage|`boolean`|`false`|(Experimental) Renders only the first page without scroll. (useful for display thumbnail)|
|
|
82
82
|
|onPageChange|`(current: number, total: number) => void`||Invoked on pages scroll.|
|
|
83
|
-
|style|`StyleProp<ViewStyle>`||Styles to be applied to the
|
|
83
|
+
|style|`StyleProp<ViewStyle>`||Styles to be applied to the native [view](https://reactnative.dev/docs/view-style-props).|
|
|
84
84
|
|
|
85
85
|
## Limitations
|
|
86
86
|
|
|
87
|
+
### Page interactions
|
|
88
|
+
|
|
89
|
+
Because Android renders the PDF page as a full image, it does not support text selection, accessibility, or handling links.
|
|
90
|
+
|
|
91
|
+
If any of these features are important for your product, we recommend adding a button to open the PDF in an external PDF viewer.
|
|
92
|
+
|
|
87
93
|
### Size measuring
|
|
88
94
|
|
|
89
|
-
The `PdfRendererView` is `flex: 1` by default, so you need to make sure that your parents `View` are `flex: 1` or have a fixed `width/height`.
|
|
95
|
+
The `PdfRendererView` is `flex: 1` by default, so you need to make sure that your parents `View`s are `flex: 1` or have a fixed `width/height`.
|
|
90
96
|
|
|
91
97
|
### Border radius
|
|
92
98
|
|
|
93
|
-
The `borderRadius` style is ignored by React Native custom view in Android and
|
|
99
|
+
The `borderRadius` style is ignored by React Native custom view in Android and crashes on iOS. (read more [#1](https://github.com/douglasjunior/react-native-pdf-renderer/issues/1#issuecomment-1483395465))
|
|
94
100
|
|
|
95
101
|
If you need `borderRadius`, the best option is to wrap the `PdfRendererView` in another `View`.
|
|
96
102
|
|
|
@@ -102,9 +108,15 @@ If you need `borderRadius`, the best option is to wrap the `PdfRendererView` in
|
|
|
102
108
|
</View>
|
|
103
109
|
```
|
|
104
110
|
|
|
111
|
+
## Mock with jest
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
jest.mock('react-native-pdf-renderer', () => require('react-native-pdf-renderer/dist/mock'));
|
|
115
|
+
```
|
|
116
|
+
|
|
105
117
|
## Contribute
|
|
106
118
|
|
|
107
|
-
New features, bug fixes and improvements are welcome! For questions and suggestions use the [issues](https://github.com/douglasjunior/react-native-pdf-renderer/issues).
|
|
119
|
+
New features, bug fixes, and improvements are welcome! For questions and suggestions use the [issues](https://github.com/douglasjunior/react-native-pdf-renderer/issues).
|
|
108
120
|
|
|
109
121
|
<a href="https://www.patreon.com/douglasjunior"><img src="http://i.imgur.com/xEO164Z.png" alt="Become a Patron!" width="200" /></a>
|
|
110
122
|
[](https://paypal.me/douglasnassif)
|
|
@@ -116,7 +128,7 @@ This lib is only possible thanks to the community help:
|
|
|
116
128
|
- RecyclerView `notifyDataSetChanged()` not working on React Native: https://stackoverflow.com/a/49381907/2826279
|
|
117
129
|
- Add pinch to zoom on RecyclerView: https://stackoverflow.com/a/37895783/2826279
|
|
118
130
|
- Using `Matrix` to handle zoom in a View: https://stackoverflow.com/a/55299327/2826279
|
|
119
|
-
-
|
|
131
|
+
- [Daniel Felipe Sartório](https://github.com/danielfelipesartorio) for the help with Android native code
|
|
120
132
|
|
|
121
133
|
## Star History
|
|
122
134
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ViewProps } from 'react-native';
|
|
2
2
|
export type PdfRendererViewPropsType = {
|
|
3
|
+
testID?: string;
|
|
3
4
|
/**
|
|
4
5
|
* Styles to be applied to the View.
|
|
5
6
|
*
|
|
@@ -40,5 +41,5 @@ export type PdfRendererViewPropsType = {
|
|
|
40
41
|
*/
|
|
41
42
|
onPageChange?: (page: number, totalPages: number) => void;
|
|
42
43
|
};
|
|
43
|
-
declare const PdfRendererView: ({ onPageChange, style, source, singlePage, distanceBetweenPages, maxZoom, }: PdfRendererViewPropsType) => JSX.Element;
|
|
44
|
+
declare const PdfRendererView: ({ testID, onPageChange, style, source, singlePage, distanceBetweenPages, maxZoom, }: PdfRendererViewPropsType) => JSX.Element;
|
|
44
45
|
export default PdfRendererView;
|
package/dist/PdfRendererView.js
CHANGED
|
@@ -24,7 +24,7 @@ const styles = StyleSheet.create({
|
|
|
24
24
|
flex: 1,
|
|
25
25
|
},
|
|
26
26
|
});
|
|
27
|
-
const PdfRendererView = ({ onPageChange, style, source, singlePage = false, distanceBetweenPages = 16, maxZoom = 5, }) => {
|
|
27
|
+
const PdfRendererView = ({ testID = undefined, onPageChange, style, source, singlePage = false, distanceBetweenPages = 16, maxZoom = 5, }) => {
|
|
28
28
|
const viewStyles = useMemo(() => [
|
|
29
29
|
styles.default,
|
|
30
30
|
style,
|
|
@@ -41,7 +41,7 @@ const PdfRendererView = ({ onPageChange, style, source, singlePage = false, dist
|
|
|
41
41
|
singlePage,
|
|
42
42
|
maxZoom,
|
|
43
43
|
}), [source, singlePage, maxZoom]);
|
|
44
|
-
return (React.createElement(PdfRendererNative, { distanceBetweenPages: distanceBetweenPages, style: viewStyles, params: params, onPageChange: handlePageChange }));
|
|
44
|
+
return (React.createElement(PdfRendererNative, { testID: testID, distanceBetweenPages: distanceBetweenPages, style: viewStyles, params: params, onPageChange: handlePageChange }));
|
|
45
45
|
};
|
|
46
46
|
export default PdfRendererView;
|
|
47
47
|
//# sourceMappingURL=PdfRendererView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PdfRendererView.js","sourceRoot":"","sources":["../src/PdfRendererView.tsx"],"names":[],"mappings":"AAAA,cAAc;AAEd,gDAAgD;AAEhD,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAE3D,iFAAiF;AACjF,kDAAkD;A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F,EACD,CAAC,KAAK,CAAC,CACR,CAAC;IAEF,MAAM,gBAAgB,GAAG,WAAW,CAClC,CAAC,KAAkD,EAAE,EAAE;QACrD,YAAY,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACtE,CAAC,EACD,CAAC,YAAY,CAAC,CACf,CAAC;IAEF,MAAM,MAAM,GAAG,OAAO,CACpB,GAAG,EAAE,CAAC,CAAC;QACL,MAAM;QACN,UAAU;QACV,OAAO;KACR,CAAC,EACF,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAC9B,CAAC;IAEF,OAAO,CACL,oBAAC,iBAAiB,IAChB,MAAM,EAAE,MAAM,EACd,oBAAoB,EAAE,oBAAoB,EAC1C,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,gBAAgB,GAC9B,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
package/dist/mock.d.ts
ADDED
package/dist/mock.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
const PdfRendererViewMock = (props) => {
|
|
4
|
+
return React.createElement(View, { testID: props.testID, style: props.style });
|
|
5
|
+
};
|
|
6
|
+
export default PdfRendererViewMock;
|
|
7
|
+
//# sourceMappingURL=mock.js.map
|
package/dist/mock.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC;AAGlC,MAAM,mBAAmB,GAAG,CAAC,KAA+B,EAAE,EAAE;IAC9D,OAAO,oBAAC,IAAI,IAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAI,CAAC;AAC5D,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -52,9 +52,11 @@ BOOL observerAdded = NO;
|
|
|
52
52
|
|
|
53
53
|
NSUInteger currentPageNumber = [view.document indexForPage:view.currentPage];
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
@
|
|
57
|
-
|
|
55
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
56
|
+
view.onPageChange(@{
|
|
57
|
+
@"position": [NSNumber numberWithInteger:currentPageNumber],
|
|
58
|
+
@"total": [NSNumber numberWithInteger:view.document.pageCount],
|
|
59
|
+
});
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
62
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-pdf-renderer",
|
|
3
3
|
"displayName": "React-Native Pdf Renderer",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.2",
|
|
5
5
|
"description": "⚛ A zoomable, blazing fast, zero dependencies, pure native, typed PDF Renderer for Android and iOS.",
|
|
6
6
|
"main": "dist",
|
|
7
7
|
"license": "MIT",
|