-
Notifications
You must be signed in to change notification settings - Fork 12
/
PSPDFKit.js
1236 lines (1151 loc) · 32.9 KB
/
PSPDFKit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// PSPDFPlugin.ios.js
// Plugin for PSPDFKit for Apache Cordova
//
// Copyright © 2013-2022 PSPDFKit GmbH. All rights reserved.
//
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY AUSTRIAN COPYRIGHT LAW
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
// This notice may not be removed from this file.
//
var exec = require("cordova/exec");
var platform = window.cordova.platformId;
// License key
/**
* Activates PSPDFKit with your license key from https://customers.pspdfkit.com.
*
* @param key The license key.
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.setLicenseKey = function(key, callback) {
executeAction(callback, "setLicenseKey", [key]);
};
/**
* Sets global options for PSPDFKit.
*
* @param options The `options` parameter. See the full list of `PSPDFSettingKeys` here: https://pspdfkit.com/api/ios/Other%20Constants.html#/c:@PSPDFSettingKeyXCallbackURLString
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.setGlobalOptions = function (options, callback) {
if (platform === "ios") {
executeAction(callback, "setGlobalOptions", [options]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
// Showing and dismissing PDF
/**
* iOS: Displays a PDF in a full-screen modal.
* Android: Opens the PSPDFActivity to show a document from the local device file system.
*
* @param path The path should be a string containing the file path (not URL) for the PDF. Relative paths are assumed to be relative to the www directory (if the path has a different base URL set, this will be ignored). To specify a path inside the application documents or library directory, use a `~`, e.g. `"~/Documents/mypdf.pdf"` or `"~/Library/Application Support/mypdf.pdf"`. Path can be null, but must not be omitted
* @param options The `options` parameter is an optional object containing configuration properties for the PDF document and/or view controller. All currently supported values for Android are listed below under Options. For all currently supported values for iOS please take a look at `enumValuesOfType` in https://github.com/PSPDFKit/PSPDFKit-Cordova/blob/master/src/ios/PSPDFKitPlugin.m.
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.present = function(path, options, callback) {
if (platform === "ios") {
executeAction(callback, "present", [path, options]);
} else if (platform === "android") {
options = options || {};
var password = getPropertyAndUnset(options, "password");
executeAction(callback, "showDocument", [path, options, password]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Opens the PSPDFActivity to show a document from the app's assets folder. This method copies the
* file to the internal app directory on the device before showing it.
*
* @param assetFile Relative path within the app's assets folder.
* @param options PSPDFKit configuration options.
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -Android
*/
exports.presentFromAssets = function(assetFile, options, callback) {
if (platform === "android") {
options = options || {};
var password = getPropertyAndUnset(options, "password");
executeAction(callback, "showDocumentFromAssets", [
assetFile,
options,
password
]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Displays a PDF in a full-screen modal and imports annotations from a given XFDF file.
*
* @param path Should be a string containing the file path (not URL) for the PDF. Relative paths are assumed to be relative to the www directory (if the path has a different base URL set, this will be ignored). To specify a path inside the application documents or library directory, use a `~`, e.g. `"~/Documents/mypdf.pdf"` or `"~/Library/Application Support/mypdf.pdf"`. Path can be null, but must not be omitted
* @param xfdfPath should be a string containing the file path (not URL) for the XFDF file backing the PDF document. Relative paths are assumed to be relative to the www directory (if the xfdf path has a different base URL set, we will create an XFDF file in `'"~/Documents/" + xfdfPath'`). To specify a path inside the application documents or library directory, use a ~, e.g. `"~/Documents/myXFDF.xfdf"` or `"~/Library/Application Support/myXFDF.xfdf"`. The xfdfPath cannot be null and must not be omitted.
* @param options The `options` parameter is an optional object containing configuration properties for the PDF document and/or view controller. All currently supported values are listed below under Options.
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.presentWithXFDF = function(path, xfdfPath, callback, options) {
if (platform === "ios") {
executeAction(callback, "presentWithXFDF", [path, xfdfPath, options]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* iOS: Dismisses the modally presented PDF view.
*
* Android: Dismisses any previously launched PDF activity. Calls the optional callback function after all activities have been dismissed.
*
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.dismiss = function(callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "dismiss", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Reloads the current PDF.
*
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.reload = function(callback) {
if (platform === "ios") {
executeAction(callback, "reload", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
// Saving
/**
* Saves the document to original location if it has been changed. If there were no changes to the
* document, the document file will not be modified.
* Provides "wasModified" as a part of a successful response which will be equal to {@code true} if
* the file was modified and changes were saved. {@code false} if there was nothing to save.
*
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -Android
*/
exports.saveDocument = function(success, error) {
if (platform === "android") {
executeAction(callback, "saveDocument", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Saves any changed annotations in the current document.
*
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.saveAnnotations = function(callback) {
if (platform === "ios") {
executeAction(callback, "saveAnnotations", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Return true in the success (or result) callback if the document has unsaved annotation. Returns false otherwise.
*
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.getHasDirtyAnnotations = function(callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "getHasDirtyAnnotations", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
// Search
/**
* Triggers a search for the specified query text.
*
* @param query Search Term to query
* @param animated Optional argument. Determines if the search should be animated (if omitted, the search will not be animated). The optional headless argument determines whether the search UI should be disaplyed (if omitted, the search UI *will* be displayed).
* @param headless Optional argument. Determines whether the search UI should be disaplyed (if omitted, the search UI *will* be displayed).
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.search = function(query, animated, headless, callback) {
if (platform === "ios") {
executeAction(callback, "search", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
// Document presentation options.
/**
* Constant values used for setting the `scrollMode` option.
*
* __Supported Platforms__
*
* -Android
*/
exports.ScrollMode = {
/**
* Paginated scrolling, will always snap to a page when user stops dragging or flinging.
*/
PER_PAGE: "PER_PAGE",
/**
* Continuous/smooth scrolling, will stop in whatever position the user stopped dragging.
*/
CONTINUOUS: "CONTINUOUS"
};
/**
* Constant values used for setting the 'pageFitMode' option.
*
* __Supported Platforms__
*
* -Android
*/
exports.PageFitMode = {
/**
* Fit the into the screen.
*/
FIT_TO_SCREEN: "FIT_TO_SCREEN",
/**
* Scale the page to fill the screen width (if possible).
*/
FIT_TO_WIDTH: "FIT_TO_WIDTH"
};
/**
* Constant values used for setting the 'pageDirection' option.
*
* __Supported Platforms__
*
* -Android
*/
exports.PageScrollDirection = {
/**
* Scroll horizontally.
*/
HORIZONTAL: "HORIZONTAL",
/**
* Scroll vertically.
*/
VERTICAL: "VERTICAL"
};
/**
* Constant values used for setting the 'searchType' option.
*
* __Supported Platforms__
*
* -Android
*/
exports.SearchType = {
/**
* Modular search window.
*/
SEARCH_MODULAR: "SEARCH_MODULAR",
/**
* Inline search (in action bar).
*/
SEARCH_INLINE: "SEARCH_INLINE"
};
/**
* Constant values used for setting the 'thumbnailBarMode' option.
*
* __Supported Platforms__
*
* -Android
*/
exports.ThumbnailBarMode = {
/**
* Default (static) thumbnail bar.
*/
THUMBNAIL_BAR_MODE_DEFAULT: "THUMBNAIL_BAR_MODE_DEFAULT",
/**
* Scrollable thumbnail bar.
*/
THUMBNAIL_BAR_MODE_SCROLLABLE: "THUMBNAIL_BAR_MODE_SCROLLABLE",
/**
* No thumbnail bar.
*/
THUMBNAIL_BAR_MODE_NONE: "THUMBNAIL_BAR_MODE_NONE"
};
/**
* Constant values used for setting the 'shareFeatures' option. These settings control the visibility
* of share actions inside the user interface.
*
* __Supported Platforms__
*
* -Android
*/
exports.ShareFeatures = {
/** Document sharing inside the activity. */
DOCUMENT_SHARING: "DOCUMENT_SHARING",
/** Sharing of embedded files (on file annotations). */
EMBEDDED_FILE_SHARING: "EMBEDDED_FILE_SHARING",
/** Sharing of text from selected free text annotations. */
FREE_TEXT_ANNOTATION_SHARING: "FREE_TEXT_ANNOTATION_SHARING",
/** Sharing of selected image annotations. */
IMAGE_SHARING: "IMAGE_SHARING",
/** Sharing of text from selected note annotations. */
NOTE_ANNOTATION_SHARING: "NOTE_ANNOTATION_SHARING",
/** Sharing of text from annotation contents or comments. */
NOTE_EDITOR_CONTENT_SHARING: "NOTE_EDITOR_CONTENT_SHARING",
/** Sharing of selected text. */
TEXT_SELECTION_SHARING: "TEXT_SELECTION_SHARING"
};
/**
* Sets multiple document and view controller settings at once.
*
* @param options The options set will be applied to the current document (if there is one) as well as all subsequently displayed documents. All currently supported values are listed below under Options.
* @param animated determines if the property should be animated. Not all property changes can be animated, so if the property does not support animation the animated argument will be ignored.
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.setOptions = function(options, animated, callback) {
if (platform === "ios") {
executeAction(callback, "setOptions", [options, animated]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Gets several document or view controller options in a single call.
*
* @param names array of option names
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.getOptions = function(names, callback) {
if (platform === "ios") {
executeAction(callback, "getOptions", [names]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Sets a single document or view controller settings at once.
*
* @param name the option name
* @param value the option value
* @param animated determines if the property should be animated. Not all property changes can be animated, so if the property does not support animation the animated argument will be ignored.
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.setOption = function(name, value, animated, callback) {
if (platform === "ios") {
executeAction(callback, "setOption", [name, value, animated]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Gets a single document or view controller settings at once.
*
* @param name the option name
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.getOption = function(name, callback) {
if (platform === "ios") {
executeAction(callback, "getOption", [name]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
// Working with page navigation
/**
* Sets the current visible page.
*
* @param page the page index
* @param animated Optional argument. Determines if the page change should be animated (if omitted, the search will not be animated).
* @callback callback Success (or result) and error callback function.
* __Supported Platforms__
*
* -iOS
*/
exports.setPage = function(page, animated, callback) {
if (platform === "ios") {
executeAction(callback, "setPage", [page, animated]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Gets the currently visible page.
*
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.getPage = function(callback) {
if (platform === "ios") {
executeAction(callback, "getPage", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Gets the page count of the current document.
*
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.getPageCount = function(callback) {
if (platform === "ios") {
executeAction(callback, "getPageCount", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Scrolls to the next page.
*
* @param animated Optional argument. Determines if the page change should be animated (if omitted, the search will not be animated).
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.scrollToNextPage = function(animated, callback) {
if (platform === "ios") {
executeAction(callback, "scrollToNextPage", [animated]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Scrolls to the previous page.
*
* @param animated Optional argument. Determines if the page change should be animated (if omitted, the search will not be animated).
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.scrollToPreviousPage = function(animated, callback) {
if (platform === "ios") {
executeAction(callback, "scrollToPreviousPage", [animated]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Sets the appearance mode.
*
* @param appearanceMode the appearance mode. Can be 'default', 'sepia', or 'night'
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.setAppearanceMode = function(appearanceMode, callback) {
if (platform === "ios") {
executeAction(callback, "setAppearanceMode", [appearanceMode]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
// Cache
/**
* Clears the entire render cache. This invalidates render caches for all previously rendered documents.
* Consider using `removeCacheForPresentedDocument()` or `clearCacheForPage()` instead of this,
* since invalidating single documents or specific page caches since excessive cache invalidation may decrease performance.
*
* @param clearDiskCache optional parameter. Android: if set to true clears disk cache as well. iOS: has no effect.
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.clearCache = function(clearDiskCache, callback) {
if (platform === "ios" || platform === "android") {
clearDiskCache = clearDiskCache || {};
executeAction(callback, "clearCache", [clearDiskCache]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Clears the cache from the currently presented document.
*
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.removeCacheForPresentedDocument = function(callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "removeCacheForPresentedDocument", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Invalidates the render cache for the specified page.
*
* @param pageIndex 0-based index of the page whose render cache should be invalidated.
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.clearCacheForPage = function(pageIndex, callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "clearCacheForPage", [pageIndex]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
// Working with toolbars
/**
* Default left bar button items
*
* __Supported Platforms__
*
* -iOS
*/
var leftBarButtonItems = ["close"];
/**
* Default right bar button items
*
* __Supported Platforms__
*
* -iOS
*/
var rightBarButtonItems = ["search", "outline", "thumbnails"];
/**
* Action for custom left bar button item.
*
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.dispatchLeftBarButtonAction = function(index) {
if (platform === "ios") {
leftBarButtonItems[index].action();
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Action for custom right bar button item.
*
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.dispatchRightBarButtonAction = function(index) {
rightBarButtonItems[index].action();
};
/**
* Sets the left bar button items.
* Note: The same button item cannot be added to both the left and right bar button items simultaneously.
*
* @param items The list of bar button items. See the full list of button items here: https://pspdfkit.com/api/ios/Classes/PSPDFViewController.html#/Toolbar%20button%20items
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.setLeftBarButtonItems = function(items) {
if (platform === "ios") {
leftBarButtonItems = items;
exec(
function(result) {},
function(error) {},
"PSPDFKitPlugin",
"setLeftBarButtonItems",
[items]
);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Sets the right bar button items.
* Note: The same button item cannot be added to both the left and right bar button items simultaneously.
*
* @param items The list of bar button items. See the full list of button items here: https://pspdfkit.com/api/ios/Classes/PSPDFViewController.html#/Toolbar%20button%20items
*
* __Supported Platforms__
*
* -iOS
*/
exports.setRightBarButtonItems = function(items) {
if (platform === "ios") {
rightBarButtonItems = items;
exec(
function(result) {},
function(error) {},
"PSPDFKitPlugin",
"setRightBarButtonItems",
[items]
);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Gets the left bar button items.
*
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.getLeftBarButtonItems = function(callback) {
if (platform === "ios") {
callback(leftBarButtonItems);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Gets the right bar button items.
*
* @callback callback Success (or result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.getRightBarButtonItems = function(callback) {
if (platform === "ios") {
callback(rightBarButtonItems);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Hides the annotation toolbar
*
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.hideAnnotationToolbar = function(callback) {
if (platform === "ios") {
executeAction(callback, "hideAnnotationToolbar", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Shows the annotation toolbar
*
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.showAnnotationToolbar = function(callback) {
if (platform === "ios") {
executeAction(callback, "showAnnotationToolbar", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Toggles the annotation toolbar
*
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
*/
exports.toggleAnnotationToolbar = function(callback) {
if (platform === "ios") {
executeAction(callback, "toggleAnnotationToolbar", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
// Instant JSON
/**
* Applies the passed in document Instant JSON.
*
* @param jsonValue The document Instant JSON to apply.
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.applyInstantJSON = function(jsonValue, callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "applyInstantJSON", [jsonValue]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Adds a new annotation to the current document using the Instant JSON Annotation
* payload - https://pspdfkit.com/guides/ios/current/importing-exporting/instant-json/#instant-annotation-json-api
*
* @param jsonAnnotation Instant JSON of the annotation to add.
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.addAnnotation = function(jsonAnnotation, callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "addAnnotation", [jsonAnnotation]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Removes a given annotation from the current document. The annotaion is expected to be in Instant
* JSON format - https://pspdfkit.com/guides/ios/current/importing-exporting/instant-json/#instant-annotation-json-api
*
* @param jsonAnnotation Instant JSON of the annotation to remove.
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.removeAnnotation = function(jsonAnnotation, callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "removeAnnotation", [jsonAnnotation]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Gets all annotations of the given type from the page.
*
* @param pageIndex The page to get the annotations for.
* @param type The type of annotations to get (See here for types https://pspdfkit.com/guides/server/current/api/json-format/) or `null` to get all annotations.
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.getAnnotations = function(pageIndex, type, callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "getAnnotations", [pageIndex, type]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Gets all unsaved changes to annotations.
*
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.getAllUnsavedAnnotations = function(callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "getAllUnsavedAnnotations", []);
} else {
console.log("Not implemented on " + platform + ".");
}
};
// Forms
/**
* Sets the value of the form element of the fully qualified name.
*
* @param value the value.
* @param fullyQualifiedName the fully qualified name of the form element.
* @callback callback Success (result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.setFormFieldValue = function(value, fullyQualifiedName, callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "setFormFieldValue", [value, fullyQualifiedName]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Gets the value of the form element of the fully qualified name.
*
* @param fullyQualifiedName description.
* @callback callback Success (result) and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.getFormFieldValue = function(fullyQualifiedName, callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "getFormFieldValue", [fullyQualifiedName]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
// XFDF
/**
* Imports all annotations from the specified XFDF file to the current document.
*
* @param xfdfPath XFDF file path to import annotations
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.importXFDF = function(xfdfPath, callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "importXFDF", [xfdfPath]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
/**
* Exports all annotations from the current document to the specified XFDF file path.
*
* @param xfdfPath XFDF file path to export annotations
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.exportXFDF = function(xfdfPath, callback) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "exportXFDF", [xfdfPath]);
} else {
console.log("Not implemented on " + platform + ".");
}
};
// Document processing
/**
* Processes annotations (embed, remove, flatten, or print) and saves the processed document to the given document path.
*
* @param annotationChange the annotation change. Can be 'flatten', 'remove', 'embed' or 'print'
* @param processedDocumentPath description.
* @param annotationType The optional string annotationType argument. If omitted, we process 'All' annotations. The annotation type can have one of the following values: None, Undefined, Link, Highlight, StrikeOut, Underline, Squiggly, FreeText, Ink, Square, Circle, Line, Text, Stamp, Caret, RichMedia, Screen, Widget, Sound, FileAttachment, Polygon, PolyLine, Popup, Watermark, TrapNet, 3D, Redact, All.
* @callback callback Success and error callback function.
*
* __Supported Platforms__
*
* -iOS
* -Android
*/
exports.processAnnotations = function(
annotationChange,
processedDocumentPath,
callback,
annotationType
) {
if (platform === "ios" || platform === "android") {
executeAction(callback, "processAnnotations", [
annotationChange,
processedDocumentPath,