@amafil/react-native-pdf-toolkit 1.0.15 → 1.1.1

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 CHANGED
@@ -13,6 +13,63 @@ A react native PDF view component (cross-platform support)
13
13
  * support password protected pdf
14
14
  * jump to a specific page in the pdf
15
15
  * auto scroll with configurable speed (ideal for music sheets)
16
+ * annotate pages with ink, text, and highlight tools
17
+
18
+ ### Annotation editing
19
+
20
+ The component accepts an annotation document through the `annotations` prop together with `annotationMode`, `annotationTool`, `annotationEditable`, and `annotationIdMode`. Ink defaults can be controlled with `annotationInkColor` and `annotationInkThickness`.
21
+
22
+ ```tsx
23
+ const annotations = {
24
+ editable: true,
25
+ idMode: 'auto',
26
+ annotations: [
27
+ {
28
+ id: 'note-1',
29
+ page: 1,
30
+ type: 'text',
31
+ bounds: {x: 0.15, y: 0.24, width: 0.28, height: 0.12},
32
+ text: 'Reminder for page one',
33
+ style: {color: '#2244aa', fontSize: 15, textAlign: 'left'},
34
+ },
35
+ {
36
+ id: 'stroke-1',
37
+ page: 2,
38
+ type: 'ink',
39
+ points: [
40
+ {x: 0.12, y: 0.18},
41
+ {x: 0.26, y: 0.22},
42
+ {x: 0.34, y: 0.19},
43
+ ],
44
+ style: {color: '#111111', thickness: 2},
45
+ },
46
+ ],
47
+ };
48
+
49
+ <Pdf
50
+ ref={pdfRef}
51
+ source={source}
52
+ annotations={annotations}
53
+ annotationMode
54
+ annotationTool="ink"
55
+ annotationInkColor="#1d4ed8"
56
+ annotationInkThickness={4}
57
+ />
58
+ ```
59
+
60
+ Supported tools are `select`, `ink`, `text`, and `highlight`.
61
+
62
+ In `select` mode, tap an annotation to select it, drag to move it, and use the resize handle to resize text and highlight annotations. Deletion is host-controlled: call `pdfRef.current.deleteSelectedAnnotation()` or `pdfRef.current.deleteAllAnnotations()` from your own UI.
63
+
64
+ Call `await pdfRef.current.saveAnnotations()` to receive the current document back from native as `{ editable, idMode, annotations }`.
65
+
66
+ Legacy `underline` and `strikeout` annotations are normalized to `highlight` when loading and saving.
67
+
68
+ Notes:
69
+
70
+ * Editing currently targets the default vertical viewer flow.
71
+ * Android editing is disabled when `horizontal`, `enablePaging`, `enableRTL`, or `singlePage` are enabled.
72
+ * iOS editing uses PDFKit when `usePDFKit` is true.
16
73
 
17
74
  ### Supported versions
18
75
  We use [`react-native-blob-util`](https://github.com/RonRadtke/react-native-blob-util) to handle file system access in this package,
@@ -139,6 +139,41 @@ public class PdfManager extends SimpleViewManager<PdfView> implements RNPDFPdfVi
139
139
  pdfView.setEnableDoubleTapZoom(enableDoubleTap);
140
140
  }
141
141
 
142
+ @ReactProp(name = "annotations")
143
+ public void setAnnotations(PdfView pdfView, @Nullable String annotations) {
144
+ pdfView.setAnnotations(annotations);
145
+ }
146
+
147
+ @ReactProp(name = "annotationMode")
148
+ public void setAnnotationMode(PdfView pdfView, boolean annotationMode) {
149
+ pdfView.setAnnotationMode(annotationMode);
150
+ }
151
+
152
+ @ReactProp(name = "annotationTool")
153
+ public void setAnnotationTool(PdfView pdfView, @Nullable String annotationTool) {
154
+ pdfView.setAnnotationTool(annotationTool);
155
+ }
156
+
157
+ @ReactProp(name = "annotationEditable")
158
+ public void setAnnotationEditable(PdfView pdfView, boolean annotationEditable) {
159
+ pdfView.setAnnotationEditable(annotationEditable);
160
+ }
161
+
162
+ @ReactProp(name = "annotationIdMode")
163
+ public void setAnnotationIdMode(PdfView pdfView, @Nullable String annotationIdMode) {
164
+ pdfView.setAnnotationIdMode(annotationIdMode);
165
+ }
166
+
167
+ @ReactProp(name = "annotationInkColor")
168
+ public void setAnnotationInkColor(PdfView pdfView, @Nullable String annotationInkColor) {
169
+ pdfView.setAnnotationInkColor(annotationInkColor);
170
+ }
171
+
172
+ @ReactProp(name = "annotationInkThickness")
173
+ public void setAnnotationInkThickness(PdfView pdfView, float annotationInkThickness) {
174
+ pdfView.setAnnotationInkThickness(annotationInkThickness);
175
+ }
176
+
142
177
  @ReactProp(name = "enablePaging")
143
178
  public void setEnablePaging(PdfView pdfView, boolean enablePaging) {
144
179
  pdfView.setEnablePaging(enablePaging);
@@ -184,9 +219,30 @@ public class PdfManager extends SimpleViewManager<PdfView> implements RNPDFPdfVi
184
219
  startNativeAutoScroll(root, args.getDouble(0), args.getDouble(1));
185
220
  } else if ("stopNativeAutoScroll".equals(commandId)) {
186
221
  stopNativeAutoScroll(root);
222
+ } else if ("saveAnnotations".equals(commandId)) {
223
+ saveAnnotations(root);
224
+ } else if ("deleteSelectedAnnotation".equals(commandId)) {
225
+ deleteSelectedAnnotation(root);
226
+ } else if ("deleteAllAnnotations".equals(commandId)) {
227
+ deleteAllAnnotations(root);
187
228
  }
188
229
  }
189
230
 
231
+ @Override
232
+ public void saveAnnotations(PdfView view) {
233
+ view.saveAnnotations();
234
+ }
235
+
236
+ @Override
237
+ public void deleteSelectedAnnotation(PdfView view) {
238
+ view.deleteSelectedAnnotation();
239
+ }
240
+
241
+ @Override
242
+ public void deleteAllAnnotations(PdfView view) {
243
+ view.deleteAllAnnotations();
244
+ }
245
+
190
246
  @Override
191
247
  public void onAfterUpdateTransaction(PdfView pdfView) {
192
248
  super.onAfterUpdateTransaction(pdfView);