@pdftron/pdfnet-node-samples 10.7.0 → 10.8.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.
Files changed (59) hide show
  1. package/package.json +21 -20
  2. package/readme.md +12 -12
  3. package/samples/AddImageTest/AddImageTest.js +115 -115
  4. package/samples/AdvancedImagingTest/AdvancedImagingTest.js +78 -78
  5. package/samples/AnnotationTest/AnnotationTest.js +641 -641
  6. package/samples/BookmarkTest/BookmarkTest.js +219 -219
  7. package/samples/CAD2PDFTest/CAD2PDFTest.js +79 -79
  8. package/samples/ContentReplacerTest/ContentReplacerTest.js +75 -75
  9. package/samples/ConvertPrintTest/ConvertPrintTest.js +153 -153
  10. package/samples/ConvertTest/ConvertTest.js +203 -203
  11. package/samples/DataExtractionTest/DataExtractionTest.js +214 -214
  12. package/samples/DigitalSignaturesTest/DigitalSignaturesTest.js +526 -526
  13. package/samples/DocumentCreationTest/DocumentCreationTest.js +409 -409
  14. package/samples/ElementBuilderTest/ElementBuilderTest.js +513 -513
  15. package/samples/ElementEditTest/ElementEditTest.js +110 -110
  16. package/samples/ElementReaderAdvTest/ElementReaderAdvTest.js +305 -305
  17. package/samples/ElementReaderTest/ElementReaderTest.js +77 -77
  18. package/samples/EncTest/EncTest.js +175 -175
  19. package/samples/FDFTest/FDFTest.js +218 -218
  20. package/samples/HTML2PDFTest/HTML2PDFTest.js +164 -164
  21. package/samples/HighlightsTest/HighlightsTest.js +97 -97
  22. package/samples/ImageExtractTest/ImageExtractTest.js +129 -129
  23. package/samples/ImpositionTest/ImpositionTest.js +86 -86
  24. package/samples/InteractiveFormsTest/InteractiveFormsTest.js +381 -381
  25. package/samples/JBIG2Test/JBIG2Test.js +88 -88
  26. package/samples/LicenseKey/LicenseKey.js +11 -11
  27. package/samples/LogicalStructureTest/LogicalStructureTest.js +250 -250
  28. package/samples/OCRTest/OCRTest.js +235 -235
  29. package/samples/OfficeTemplateTest/OfficeTemplateTest.js +79 -79
  30. package/samples/OfficeToPDFTest/OfficeToPDFTest.js +125 -125
  31. package/samples/OptimizerTest/OptimizerTest.js +191 -191
  32. package/samples/PDF2HtmlTest/PDF2HtmlTest.js +123 -123
  33. package/samples/PDF2OfficeTest/PDF2OfficeTest.js +158 -158
  34. package/samples/PDFATest/PDFATest.js +85 -85
  35. package/samples/PDFDocMemoryTest/PDFDocMemoryTest.js +84 -84
  36. package/samples/PDFDrawTest/PDFDrawTest.js +305 -305
  37. package/samples/PDFLayersTest/PDFLayersTest.js +294 -294
  38. package/samples/PDFPackageTest/PDFPackageTest.js +111 -111
  39. package/samples/PDFPageTest/PDFPageTest.js +189 -189
  40. package/samples/PDFRedactTest/PDFRedactTest.js +74 -74
  41. package/samples/PageLabelsTest/PageLabelsTest.js +138 -138
  42. package/samples/PatternTest/PatternTest.js +226 -226
  43. package/samples/RectTest/RectTest.js +40 -40
  44. package/samples/SDFTest/SDFTest.js +87 -87
  45. package/samples/StamperTest/StamperTest.js +255 -255
  46. package/samples/TestFiles/Misc-Fixed.pfa +1166 -1166
  47. package/samples/TestFiles/SHA-2 Root USERTrust RSA CA Sectigo timestamping.crt +34 -34
  48. package/samples/TestFiles/form1_annots.xfdf +33 -33
  49. package/samples/TestFiles/form1_data.xfdf +139 -139
  50. package/samples/TestFiles/my_stream.txt +2310 -2310
  51. package/samples/TestFiles/tiger.svg +378 -378
  52. package/samples/TextExtractTest/TextExtractTest.js +286 -286
  53. package/samples/TextSearchTest/TextSearchTest.js +121 -121
  54. package/samples/U3DTest/U3DTest.js +104 -104
  55. package/samples/UndoRedoTest/UndoRedoTest.js +101 -101
  56. package/samples/UnicodeWriteTest/UnicodeWriteTest.js +173 -173
  57. package/samples/WebViewerConvertTest/WebViewerConvertTest.js +135 -135
  58. package/samples/runall.bat +12 -12
  59. package/samples/runall.sh +15 -15
@@ -1,642 +1,642 @@
1
- //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3
- // Consult legal.txt regarding legal and license information.
4
- //---------------------------------------------------------------------------------------
5
-
6
-
7
- const { PDFNet } = require('@pdftron/pdfnet-node');
8
- const PDFTronLicense = require('../LicenseKey/LicenseKey');
9
-
10
- ((exports) => {
11
- exports.runAnnotationTest = async() => {
12
-
13
- const inputPath = '../TestFiles/';
14
-
15
- const AnnotationHighLevelAPI = async(doc) => {
16
- await PDFNet.startDeallocateStack(); // start stack-based deallocation. All objects will be deallocated by end of function
17
-
18
- // The following code snippet traverses all annotations in the document
19
- console.log('Traversing all annotations in the document...');
20
-
21
- let pageNum = 0;
22
- const itr = await doc.getPageIterator();
23
- for (itr; (await itr.hasNext()); (await itr.next())) {
24
- pageNum += 1;
25
- console.log('Page ' + pageNum + ': ');
26
- const page = await itr.current();
27
- const numAnnots = await page.getNumAnnots();
28
- for (let i = 0; i < numAnnots; ++i) {
29
- const annot = await page.getAnnot(i);
30
- if (!(await annot.isValid())) {
31
- continue;
32
- }
33
-
34
- const annotSDF = await annot.getSDFObj();
35
- const subType = await annotSDF.get('Subtype');
36
- const subTypeVal = await subType.value();
37
-
38
- let outputString = 'Annot Type: ' + (await subTypeVal.getName());
39
- console.log(outputString);
40
- const bbox = await annot.getRect();
41
- outputString = ' Position: ' + bbox.x1 + ', ' + bbox.y1 + ', ' + bbox.x2 + ', ' + bbox.y2;
42
- console.log(outputString);
43
- const annotType = await annot.getType();
44
- switch (annotType) {
45
- case PDFNet.Annot.Type.e_Link:
46
- {
47
- const link = await PDFNet.LinkAnnot.createFromAnnot(annot);
48
- const action = await link.getAction();
49
- if (!(await action.isValid())) {
50
- continue;
51
- }
52
-
53
- if ((await action.getType()) === PDFNet.Action.Type.e_GoTo) {
54
- const dest = await action.getDest();
55
- if (!(await dest.isValid())) {
56
- console.log(' Destination is not valid');
57
- } else {
58
- const pageNumOut = await (await dest.getPage()).getIndex();
59
- console.log(' Links to: page number ' + pageNumOut + ' in this document');
60
- }
61
- } else if ((await action.getType()) === PDFNet.Action.Type.e_URI) {
62
- const SDFObj = await action.getSDFObj();
63
- const URI = await SDFObj.get('URI');
64
- const URIval = await URI.value();
65
- const URIText = await URIval.getAsPDFText(); // An Exception is thrown if this is not a Obj::Type::e_string.
66
- console.log(' Links to: ' + URIText); // Other get methods such as getNumber do not work either, although some do, so confusing.
67
- // deallocate dictionary object on C side
68
- URI.destroy();
69
- }
70
- }
71
- break;
72
- case PDFNet.Annot.Type.e_Widget:
73
- break;
74
- case PDFNet.Annot.Type.e_FileAttachment:
75
- break;
76
- default:
77
- break;
78
- }
79
-
80
- await subType.destroy();
81
- }
82
- }
83
- // create a hyperlink
84
- const firstPage = await doc.getPage(1);
85
- const createURIAction = await PDFNet.Action.createURI(doc, 'http://www.pdftron.com');
86
- const linkRect = new PDFNet.Rect(85, 570, 503, 524);
87
- const hyperlink = await PDFNet.LinkAnnot.create(doc, linkRect);
88
- await hyperlink.setAction(createURIAction);
89
- await firstPage.annotPushBack(hyperlink);
90
-
91
- // Create an intra-document link...
92
- const page3 = await doc.getPage(3);
93
- const gotoPage3 = await PDFNet.Action.createGoto(await PDFNet.Destination.createFitH(page3, 0));
94
- const link = await PDFNet.LinkAnnot.create(doc, (new PDFNet.Rect(85, 458, 503, 502)));
95
- await link.setAction(gotoPage3);
96
- const greenColorPt = await PDFNet.ColorPt.init(0, 0, 1);
97
- await link.setColor(greenColorPt);
98
-
99
- // Add the new annotation to the first page
100
- await firstPage.annotPushBack(link);
101
-
102
- // Create a stamp annotation ...
103
- const stamp = await PDFNet.RubberStampAnnot.create(doc, (new PDFNet.Rect(30, 30, 300, 200)));
104
- await stamp.setIconName('Draft');
105
- await firstPage.annotPushBack(stamp);
106
-
107
- // Create a file attachment annotation (embed the 'peppers.jpg').
108
- const file_attach = await PDFNet.FileAttachmentAnnot.createDefault(doc, (new PDFNet.Rect(80, 280, 108, 320)), inputPath + 'peppers.jpg');
109
- await firstPage.annotPushBack(file_attach);
110
-
111
- const ink = await PDFNet.InkAnnot.create(doc, (new PDFNet.Rect(110, 10, 300, 200)));
112
- const pt3 = new PDFNet.Point(110, 10);
113
- await ink.setPoint(0, 0, pt3);
114
- pt3.x = 150;
115
- pt3.y = 50;
116
- await ink.setPoint(0, 1, pt3);
117
- pt3.x = 190;
118
- pt3.y = 60;
119
- await ink.setPoint(0, 2, pt3);
120
- pt3.x = 180;
121
- pt3.y = 90;
122
- await ink.setPoint(1, 0, pt3);
123
- pt3.x = 190;
124
- pt3.y = 95;
125
- await ink.setPoint(1, 1, pt3);
126
- pt3.x = 200;
127
- pt3.y = 100;
128
- await ink.setPoint(1, 2, pt3);
129
- pt3.x = 166;
130
- pt3.y = 86;
131
- await ink.setPoint(2, 0, pt3);
132
- pt3.x = 196;
133
- pt3.y = 96;
134
- await ink.setPoint(2, 1, pt3);
135
- pt3.x = 221;
136
- pt3.y = 121;
137
- await ink.setPoint(2, 2, pt3);
138
- pt3.x = 288;
139
- pt3.y = 188;
140
- await ink.setPoint(2, 3, pt3);
141
- const cyanColorPt = await PDFNet.ColorPt.init(0, 1, 1);
142
- await ink.setColor(cyanColorPt, 3);
143
- firstPage.annotPushBack(ink);
144
-
145
- await PDFNet.endDeallocateStack();
146
- };
147
-
148
- const AnnotationLowLevelAPI = async(doc) => {
149
- try {
150
- await PDFNet.startDeallocateStack(); // start stack-based deallocation. All objects will be deallocated by end of function
151
- const itr = await doc.getPageIterator();
152
- const page = await itr.current();
153
-
154
- let annots = await page.getAnnots();
155
-
156
- if (annots == null) {
157
- // If there are no annotations, create a new annotation
158
- // array for the page.
159
- annots = await doc.createIndirectArray();
160
- const sdfDoc = await page.getSDFObj();
161
- await sdfDoc.put('Annots', annots);
162
- }
163
-
164
- // Create a Text annotation
165
- const annot = await doc.createIndirectDict();
166
- await annot.putName('Subtype', 'Text');
167
- await annot.putBool('Open', true);
168
- await annot.putString('Contents', 'The quick brown fox ate the lazy mouse.');
169
- await annot.putRect('Rect', 266, 116, 430, 204);
170
-
171
- // Insert the annotation in the page annotation array
172
- await annots.pushBack(annot);
173
-
174
- // Create a Link annotation
175
- const link1 = await doc.createIndirectDict();
176
- await link1.putName('Subtype', 'Link');
177
- const dest = await PDFNet.Destination.createFit((await doc.getPage(2)));
178
- await link1.put('Dest', (await dest.getSDFObj()));
179
- await link1.putRect('Rect', 85, 705, 503, 661);
180
- await annots.pushBack(link1);
181
-
182
- // Create another Link annotation
183
- const link2 = await doc.createIndirectDict();
184
- await link2.putName('Subtype', 'Link');
185
- const dest2 = await PDFNet.Destination.createFit((await doc.getPage(3)));
186
- await link2.put('Dest', (await dest2.getSDFObj()));
187
- await link2.putRect('Rect', 85, 638, 503, 594);
188
- await annots.pushBack(link2);
189
-
190
- // link2 = annots.GetAt(annots.Size()-1);
191
- const tenthPage = await doc.getPage(10);
192
- // XYZ destination stands for 'left', 'top' and 'zoom' coordinates
193
- const XYZDestination = await PDFNet.Destination.createXYZ(tenthPage, 100, 722, 10);
194
- await link2.put('Dest', (await XYZDestination.getSDFObj()));
195
-
196
- // Create a third link annotation with a hyperlink action (all other
197
- // annotation types can be created in a similar way)
198
- const link3 = await doc.createIndirectDict();
199
- await link3.putName('Subtype', 'Link');
200
- await link3.putRect('Rect', 85, 570, 503, 524);
201
-
202
- // Create a URI action
203
- const action = await link3.putDict('A');
204
- await action.putName('S', 'URI');
205
- await action.putString('URI', 'http://www.pdftron.com');
206
-
207
- await annots.pushBack(link3);
208
- await PDFNet.endDeallocateStack();
209
- } catch (err) {
210
- console.log(err);
211
- }
212
- };
213
-
214
- const CreateTestAnnots = async(doc) => {
215
- await PDFNet.startDeallocateStack();
216
- const ew = await PDFNet.ElementWriter.create(); // elementWriter
217
- const eb = await PDFNet.ElementBuilder.create(); // elementBuilder
218
- let element;
219
-
220
- const firstPage = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
221
- doc.pagePushBack(firstPage);
222
- ew.beginOnPage(firstPage, PDFNet.ElementWriter.WriteMode.e_overlay, false); // begin writing to this page
223
- ew.end(); // save changes to the current page
224
-
225
- // NOTE: The following code represents three different ways to create a text annotation.
226
- {
227
- const txtannot = await PDFNet.FreeTextAnnot.create(doc, new PDFNet.Rect(10, 400, 160, 570));
228
- await txtannot.setContents('\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare.\n\nAha!\n\nAnd there was much rejoicing!');
229
- const solidLine = await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 1, 10, 20);
230
- await txtannot.setBorderStyle(solidLine, false);
231
- await txtannot.setQuaddingFormat(0);
232
- await firstPage.annotPushBack(txtannot);
233
- await txtannot.refreshAppearance();
234
- }
235
-
236
- {
237
- const txtannot = await PDFNet.FreeTextAnnot.create(doc, new PDFNet.Rect(100, 100, 350, 500));
238
- await txtannot.setContentRect(new PDFNet.Rect(200, 200, 350, 500));
239
- await txtannot.setContents('\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare.\n\nAha!\n\nAnd there was much rejoicing!');
240
- await txtannot.setCalloutLinePoints(new PDFNet.Point(200, 300), new PDFNet.Point(150, 290), new PDFNet.Point(110, 110));
241
- const solidLine = await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 1, 10, 20);
242
- await txtannot.setBorderStyle(solidLine, false);
243
- await txtannot.setEndingStyle(PDFNet.LineAnnot.EndingStyle.e_ClosedArrow);
244
- const greenColorPt = await PDFNet.ColorPt.init(0, 1, 0);
245
- await txtannot.setColorDefault(greenColorPt); // default value of last param is 0
246
- await txtannot.setQuaddingFormat(1);
247
- await firstPage.annotPushBack(txtannot);
248
- await txtannot.refreshAppearance();
249
- }
250
- {
251
- const txtannot = await PDFNet.FreeTextAnnot.create(doc, new PDFNet.Rect(400, 10, 550, 400));
252
- await txtannot.setContents('\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare.\n\nAha!\n\nAnd there was much rejoicing!');
253
- const solidLine = await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 1, 10, 20);
254
- await txtannot.setBorderStyle(solidLine, false);
255
- const redColorPt = await PDFNet.ColorPt.init(0, 0, 1);
256
- await txtannot.setColorDefault(redColorPt);
257
- await txtannot.setOpacity(0.2);
258
- await txtannot.setQuaddingFormat(2);
259
- await firstPage.annotPushBack(txtannot);
260
- await txtannot.refreshAppearance();
261
- }
262
- const page = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
263
- doc.pagePushBack(page);
264
- await ew.beginOnPage(page, PDFNet.ElementWriter.WriteMode.e_overlay, false);
265
- await eb.reset();
266
- await ew.end(); // save changes to the current page
267
- {
268
- // Create a Line annotation...
269
- const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(250, 250, 400, 400));
270
- await line.setStartPoint(new PDFNet.Point(350, 270));
271
- await line.setEndPoint(new PDFNet.Point(260, 370));
272
- await line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Square);
273
- await line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
274
- const darkGreenColorPt = await PDFNet.ColorPt.init(0.3, 0.5, 0);
275
- await line.setColor(darkGreenColorPt, 3);
276
- await line.setContents('Dashed Captioned');
277
- await line.setShowCaption(true);
278
- await line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
279
- const dash = [2.0, 2.0];
280
- const bStyle = await PDFNet.AnnotBorderStyle.createWithDashPattern(PDFNet.AnnotBorderStyle.Style.e_dashed, 2, 0, 0, dash);
281
- line.setBorderStyle(bStyle);
282
- line.refreshAppearance();
283
- page.annotPushBack(line);
284
- }
285
- {
286
- const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(347, 377, 600, 600));
287
- await line.setStartPoint(new PDFNet.Point(385, 410));
288
- await line.setEndPoint(new PDFNet.Point(540, 555));
289
- await line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
290
- await line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_OpenArrow);
291
- const redColorPt = await PDFNet.ColorPt.init(1, 0, 0);
292
- await line.setColor(redColorPt, 3);
293
- const greenColorPt = await PDFNet.ColorPt.init(0, 1, 0);
294
- await line.setInteriorColor(greenColorPt, 3);
295
- await line.setContents('Inline Caption');
296
- await line.setShowCaption(true);
297
- await line.setCapPos(PDFNet.LineAnnot.CapPos.e_Inline);
298
- await line.setLeaderLineExtensionLength(-4.0);
299
- await line.setLeaderLineLength(-12);
300
- await line.setLeaderLineOffset(2.0);
301
- await line.refreshAppearance();
302
- page.annotPushBack(line);
303
- }
304
- {
305
- const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(10, 400, 200, 600));
306
- await line.setStartPoint(new PDFNet.Point(25, 426));
307
- await line.setEndPoint(new PDFNet.Point(180, 555));
308
- await line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
309
- await line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_Square);
310
- const blueColorPt = await PDFNet.ColorPt.init(0, 0, 1);
311
- await line.setColor(blueColorPt, 3);
312
- const redColorPt = await PDFNet.ColorPt.init(1, 0, 0);
313
- await line.setInteriorColor(redColorPt, 3);
314
- await line.setContents('Offset Caption');
315
- await line.setShowCaption(true);
316
- await line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
317
- await line.setTextHOffset(-60);
318
- await line.setTextVOffset(10);
319
- await line.refreshAppearance();
320
- page.annotPushBack(line);
321
- }
322
- {
323
- const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(200, 10, 400, 70));
324
- line.setStartPoint(new PDFNet.Point(220, 25));
325
- line.setEndPoint(new PDFNet.Point(370, 60));
326
- line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Butt);
327
- line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_OpenArrow);
328
- line.setColor((await PDFNet.ColorPt.init(0, 0, 1)), 3);
329
- line.setContents('Regular Caption');
330
- line.setShowCaption(true);
331
- line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
332
- await line.refreshAppearance();
333
- page.annotPushBack(line);
334
- }
335
- {
336
- const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(200, 70, 400, 130));
337
- line.setStartPoint(new PDFNet.Point(220, 111));
338
- line.setEndPoint(new PDFNet.Point(370, 78));
339
- line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
340
- line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_Diamond);
341
- line.setContents('Circle to Diamond');
342
- line.setColor((await PDFNet.ColorPt.init(0, 0, 1)), 3);
343
- line.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
344
- line.setShowCaption(true);
345
- line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
346
- line.refreshAppearance();
347
- page.annotPushBack(line);
348
- }
349
- {
350
- const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(10, 100, 160, 200));
351
- line.setStartPoint(new PDFNet.Point(15, 110));
352
- line.setEndPoint(new PDFNet.Point(150, 190));
353
- line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Slash);
354
- line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_ClosedArrow);
355
- line.setContents('Slash to CArrow');
356
- line.setColor((await PDFNet.ColorPt.init(1, 0, 0)), 3);
357
- line.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 1)), 3);
358
- line.setShowCaption(true);
359
- line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
360
- line.refreshAppearance();
361
- page.annotPushBack(line);
362
- }
363
- {
364
- const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(270, 270, 570, 433));
365
- line.setStartPoint(new PDFNet.Point(300, 400));
366
- line.setEndPoint(new PDFNet.Point(550, 300));
367
- line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_RClosedArrow);
368
- line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_ROpenArrow);
369
- line.setContents('ROpen & RClosed arrows');
370
- line.setColor((await PDFNet.ColorPt.init(0, 0, 1)), 3);
371
- line.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
372
- line.setShowCaption(true);
373
- line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
374
- line.refreshAppearance();
375
- page.annotPushBack(line);
376
- }
377
- {
378
- const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(195, 395, 205, 505));
379
- line.setStartPoint(new PDFNet.Point(200, 400));
380
- line.setEndPoint(new PDFNet.Point(200, 500));
381
- line.refreshAppearance();
382
- page.annotPushBack(line);
383
- }
384
- {
385
- const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(55, 299, 150, 301));
386
- line.setStartPoint(new PDFNet.Point(55, 300));
387
- line.setEndPoint(new PDFNet.Point(155, 300));
388
- line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
389
- line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
390
- line.setContents(("Caption that's longer than its line."));
391
- line.setColor((await PDFNet.ColorPt.init(1, 0, 1)), 3);
392
- line.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
393
- line.setShowCaption(true);
394
- line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
395
- line.refreshAppearance();
396
- page.annotPushBack(line);
397
- }
398
- {
399
- const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(300, 200, 390, 234));
400
- line.setStartPoint(new PDFNet.Point(310, 210));
401
- line.setEndPoint(new PDFNet.Point(380, 220));
402
- line.setColor((await PDFNet.ColorPt.init(0, 0, 0)), 3);
403
- line.refreshAppearance();
404
- page.annotPushBack(line);
405
- }
406
- const page3 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
407
- ew.beginOnPage(page3); // begin writing to the page
408
- ew.end(); // save changes to the current page
409
- doc.pagePushBack(page3);
410
- {
411
- const circle = await PDFNet.CircleAnnot.create(doc, new PDFNet.Rect(300, 300, 390, 350));
412
- circle.setColor((await PDFNet.ColorPt.init(0, 0, 0)), 3);
413
- circle.refreshAppearance();
414
- page3.annotPushBack(circle);
415
- }
416
- {
417
- const circle = await PDFNet.CircleAnnot.create(doc, new PDFNet.Rect(100, 100, 200, 200));
418
- circle.setColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
419
- circle.setInteriorColor((await PDFNet.ColorPt.init(0, 0, 1)), 3);
420
- const dash = [2, 4];
421
- circle.setBorderStyle((await PDFNet.AnnotBorderStyle.createWithDashPattern(PDFNet.AnnotBorderStyle.Style.e_dashed, 3, 0, 0, dash)));
422
- circle.setPadding(new PDFNet.Rect(2, 2, 2, 2));
423
- circle.refreshAppearance();
424
- page3.annotPushBack(circle);
425
- }
426
- {
427
- const sq = await PDFNet.SquareAnnot.create(doc, new PDFNet.Rect(10, 200, 80, 300));
428
- sq.setColor((await PDFNet.ColorPt.init(0, 0, 0)), 3);
429
- sq.refreshAppearance();
430
- page3.annotPushBack(sq);
431
- }
432
-
433
- {
434
- const sq = await PDFNet.SquareAnnot.create(doc, new PDFNet.Rect(500, 200, 580, 300));
435
- sq.setColor((await PDFNet.ColorPt.init(1, 0, 0)), 3);
436
- sq.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 1)), 3);
437
- const dash = [4, 2];
438
- sq.setBorderStyle((await PDFNet.AnnotBorderStyle.createWithDashPattern(PDFNet.AnnotBorderStyle.Style.e_dashed, 6, 0, 0, dash)));
439
- sq.setPadding(new PDFNet.Rect(4, 4, 4, 4));
440
- sq.refreshAppearance();
441
- page3.annotPushBack(sq);
442
- }
443
-
444
- {
445
- const poly = await PDFNet.PolygonAnnot.create(doc, new PDFNet.Rect(5, 500, 125, 590));
446
- poly.setColor((await PDFNet.ColorPt.init(1, 0, 0)), 3);
447
- poly.setInteriorColor((await PDFNet.ColorPt.init(1, 1, 0)), 3);
448
- poly.setVertex(0, new PDFNet.Point(12, 510));
449
- poly.setVertex(1, new PDFNet.Point(100, 510));
450
- poly.setVertex(2, new PDFNet.Point(100, 555));
451
- poly.setVertex(3, new PDFNet.Point(35, 544));
452
- const solidBorderStyle = await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 4, 0, 0);
453
- poly.setBorderStyle(solidBorderStyle);
454
- poly.setPadding(new PDFNet.Rect(4, 4, 4, 4));
455
- poly.refreshAppearance();
456
- page3.annotPushBack(poly);
457
- }
458
- {
459
- const poly = await PDFNet.PolyLineAnnot.create(doc, new PDFNet.Rect(400, 10, 500, 90));
460
- poly.setColor((await PDFNet.ColorPt.init(1, 0, 0)), 3);
461
- poly.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
462
- poly.setVertex(0, new PDFNet.Point(405, 20));
463
- poly.setVertex(1, new PDFNet.Point(440, 40));
464
- poly.setVertex(2, new PDFNet.Point(410, 60));
465
- poly.setVertex(3, new PDFNet.Point(470, 80));
466
- poly.setBorderStyle(await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 2, 0, 0));
467
- poly.setPadding(new PDFNet.Rect(4, 4, 4, 4));
468
- poly.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_RClosedArrow);
469
- poly.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_ClosedArrow);
470
- poly.refreshAppearance();
471
- page3.annotPushBack(poly);
472
- }
473
- {
474
- const lk = await PDFNet.LinkAnnot.create(doc, new PDFNet.Rect(5, 5, 55, 24));
475
- // lk.setColor(await PDFNet.ColorPt.init(0,1,0), 3 );
476
- lk.refreshAppearance();
477
- page3.annotPushBack(lk);
478
- }
479
-
480
- const page4 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
481
- ew.beginOnPage(page4); // begin writing to the page
482
- ew.end(); // save changes to the current page
483
- doc.pagePushBack(page4);
484
-
485
- {
486
- ew.beginOnPage(page4);
487
- const font = await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_helvetica);
488
- element = await eb.createTextBeginWithFont(font, 16);
489
- element.setPathFill(true);
490
- ew.writeElement(element);
491
- element = await eb.createTextRun('Some random text on the page', font, 16);
492
- element.setTextMatrixEntries(1, 0, 0, 1, 100, 500);
493
- ew.writeElement(element);
494
- ew.writeElement((await eb.createTextEnd()));
495
- ew.end();
496
- }
497
- {
498
- const hl = await PDFNet.HighlightAnnot.create(doc, new PDFNet.Rect(100, 490, 150, 515));
499
- hl.setColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
500
- hl.refreshAppearance();
501
- page4.annotPushBack(hl);
502
- }
503
- {
504
- const sq = await PDFNet.SquigglyAnnot.create(doc, new PDFNet.Rect(100, 450, 250, 600));
505
- // sq.setColor(await PDFNet.ColorPt.init(1,0,0), 3 );
506
- sq.setQuadPoint(0, new PDFNet.QuadPoint(122, 455, 240, 545, 230, 595, 101, 500));
507
- sq.refreshAppearance();
508
- page4.annotPushBack(sq);
509
- }
510
- {
511
- const cr = await PDFNet.CaretAnnot.create(doc, new PDFNet.Rect(100, 40, 129, 69));
512
- cr.setColor((await PDFNet.ColorPt.init(0, 0, 1)), 3);
513
- cr.setSymbol('P');
514
- cr.refreshAppearance();
515
- page4.annotPushBack(cr);
516
- }
517
-
518
-
519
- const page5 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
520
- ew.beginOnPage(page5); // begin writing to the page
521
- ew.end(); // save changes to the current page
522
- doc.pagePushBack(page5);
523
- const fs = await PDFNet.FileSpec.create(doc, inputPath + 'butterfly.png', false);
524
- const page6 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
525
- ew.beginOnPage(page6); // begin writing to the page
526
- ew.end(); // save changes to the current page
527
- doc.pagePushBack(page6);
528
-
529
- {
530
- const txt = await PDFNet.TextAnnot.create(doc, new PDFNet.Rect(10, 20, 30, 40));
531
- txt.setIconName('UserIcon');
532
- txt.setContents('User defined icon, unrecognized by appearance generator');
533
- txt.setColor((await PDFNet.ColorPt.init(0, 1, 0)));
534
- txt.refreshAppearance();
535
- page6.annotPushBack(txt);
536
- }
537
- {
538
- const ink = await PDFNet.InkAnnot.create(doc, new PDFNet.Rect(100, 400, 200, 550));
539
- ink.setColor((await PDFNet.ColorPt.init(0, 0, 1)));
540
- ink.setPoint(1, 3, new PDFNet.Point(220, 505));
541
- ink.setPoint(1, 0, new PDFNet.Point(100, 490));
542
- ink.setPoint(0, 1, new PDFNet.Point(120, 410));
543
- ink.setPoint(0, 0, new PDFNet.Point(100, 400));
544
- ink.setPoint(1, 2, new PDFNet.Point(180, 490));
545
- ink.setPoint(1, 1, new PDFNet.Point(140, 440));
546
- ink.setBorderStyle(await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 3, 0, 0));
547
- ink.refreshAppearance();
548
- page6.annotPushBack(ink);
549
- }
550
-
551
-
552
- const page7 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
553
- ew.beginOnPage(page7); // begin writing to the page
554
- ew.end(); // save changes to the current page
555
- doc.pagePushBack(page7);
556
-
557
- {
558
- const snd = await PDFNet.SoundAnnot.create(doc, new PDFNet.Rect(100, 500, 120, 520));
559
- snd.setColor((await PDFNet.ColorPt.init(1, 1, 0)));
560
- snd.setIcon(PDFNet.SoundAnnot.Icon.e_Speaker);
561
- snd.refreshAppearance();
562
- page7.annotPushBack(snd);
563
- }
564
- {
565
- const snd = await PDFNet.SoundAnnot.create(doc, new PDFNet.Rect(200, 500, 220, 520));
566
- snd.setColor((await PDFNet.ColorPt.init(1, 1, 0)));
567
- snd.setIcon(PDFNet.SoundAnnot.Icon.e_Mic);
568
- snd.refreshAppearance();
569
- page7.annotPushBack(snd);
570
- }
571
-
572
- const page8 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
573
- ew.beginOnPage(page8); // begin writing to the page
574
- ew.end(); // save changes to the current page
575
- doc.pagePushBack(page8);
576
-
577
- for (let ipage = 0; ipage < 2; ++ipage) {
578
- let px = 5;
579
- let py = 520;
580
- for (let istamp = PDFNet.RubberStampAnnot.Icon.e_Approved; istamp <= PDFNet.RubberStampAnnot.Icon.e_Draft; istamp++) {
581
- const st = await PDFNet.RubberStampAnnot.create(doc, new PDFNet.Rect(1, 1, 100, 100));
582
- st.setIcon(istamp);
583
- st.setContents((await st.getIconName()));
584
- st.setRect(new PDFNet.Rect(px, py, px + 100, py + 25));
585
- py -= 100;
586
- if (py < 0) {
587
- py = 520;
588
- px += 200;
589
- }
590
- if (ipage === 0) {
591
- // page7.annotPushBack( st );
592
- } else {
593
- page8.annotPushBack(st);
594
- st.refreshAppearance();
595
- }
596
- }
597
- }
598
- const st = await PDFNet.RubberStampAnnot.create(doc, new PDFNet.Rect(400, 5, 550, 45));
599
- st.setIconName('UserStamp');
600
- st.setContents('User defined stamp');
601
- page8.annotPushBack(st);
602
- st.refreshAppearance();
603
-
604
- await PDFNet.endDeallocateStack();
605
- };
606
-
607
- const main = async() => {
608
- try {
609
- const ret = 0;
610
-
611
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'numbered.pdf');
612
- doc.initSecurityHandler();
613
-
614
-
615
- await AnnotationLowLevelAPI(doc);
616
- await doc.save(inputPath + 'Output/annotation_test1.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
617
-
618
- console.log('Done. Results saved in annotation_test1.pdf');
619
-
620
- // eslint-disable-next-line no-unused-vars
621
- const firstPage = await doc.getPage(1);
622
-
623
- await AnnotationHighLevelAPI(doc);
624
- await doc.save(inputPath + 'Output/annotation_test2.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
625
- console.log('Done. Results saved in annotation_test2.pdf');
626
-
627
- // creating various annotations in a brand new document
628
- const docnew = await PDFNet.PDFDoc.create();
629
- await CreateTestAnnots(docnew);
630
- await docnew.save(inputPath + 'Output/new_annot_test_api.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
631
- console.log('Saved new_annot_test_api.pdf');
632
- return ret;
633
- } catch (err) {
634
- console.log(err);
635
- }
636
- };
637
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
638
- };
639
- exports.runAnnotationTest();
640
- })(exports);
641
- // eslint-disable-next-line spaced-comment
1
+ //---------------------------------------------------------------------------------------
2
+ // Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3
+ // Consult legal.txt regarding legal and license information.
4
+ //---------------------------------------------------------------------------------------
5
+
6
+
7
+ const { PDFNet } = require('@pdftron/pdfnet-node');
8
+ const PDFTronLicense = require('../LicenseKey/LicenseKey');
9
+
10
+ ((exports) => {
11
+ exports.runAnnotationTest = async() => {
12
+
13
+ const inputPath = '../TestFiles/';
14
+
15
+ const AnnotationHighLevelAPI = async(doc) => {
16
+ await PDFNet.startDeallocateStack(); // start stack-based deallocation. All objects will be deallocated by end of function
17
+
18
+ // The following code snippet traverses all annotations in the document
19
+ console.log('Traversing all annotations in the document...');
20
+
21
+ let pageNum = 0;
22
+ const itr = await doc.getPageIterator();
23
+ for (itr; (await itr.hasNext()); (await itr.next())) {
24
+ pageNum += 1;
25
+ console.log('Page ' + pageNum + ': ');
26
+ const page = await itr.current();
27
+ const numAnnots = await page.getNumAnnots();
28
+ for (let i = 0; i < numAnnots; ++i) {
29
+ const annot = await page.getAnnot(i);
30
+ if (!(await annot.isValid())) {
31
+ continue;
32
+ }
33
+
34
+ const annotSDF = await annot.getSDFObj();
35
+ const subType = await annotSDF.get('Subtype');
36
+ const subTypeVal = await subType.value();
37
+
38
+ let outputString = 'Annot Type: ' + (await subTypeVal.getName());
39
+ console.log(outputString);
40
+ const bbox = await annot.getRect();
41
+ outputString = ' Position: ' + bbox.x1 + ', ' + bbox.y1 + ', ' + bbox.x2 + ', ' + bbox.y2;
42
+ console.log(outputString);
43
+ const annotType = await annot.getType();
44
+ switch (annotType) {
45
+ case PDFNet.Annot.Type.e_Link:
46
+ {
47
+ const link = await PDFNet.LinkAnnot.createFromAnnot(annot);
48
+ const action = await link.getAction();
49
+ if (!(await action.isValid())) {
50
+ continue;
51
+ }
52
+
53
+ if ((await action.getType()) === PDFNet.Action.Type.e_GoTo) {
54
+ const dest = await action.getDest();
55
+ if (!(await dest.isValid())) {
56
+ console.log(' Destination is not valid');
57
+ } else {
58
+ const pageNumOut = await (await dest.getPage()).getIndex();
59
+ console.log(' Links to: page number ' + pageNumOut + ' in this document');
60
+ }
61
+ } else if ((await action.getType()) === PDFNet.Action.Type.e_URI) {
62
+ const SDFObj = await action.getSDFObj();
63
+ const URI = await SDFObj.get('URI');
64
+ const URIval = await URI.value();
65
+ const URIText = await URIval.getAsPDFText(); // An Exception is thrown if this is not a Obj::Type::e_string.
66
+ console.log(' Links to: ' + URIText); // Other get methods such as getNumber do not work either, although some do, so confusing.
67
+ // deallocate dictionary object on C side
68
+ URI.destroy();
69
+ }
70
+ }
71
+ break;
72
+ case PDFNet.Annot.Type.e_Widget:
73
+ break;
74
+ case PDFNet.Annot.Type.e_FileAttachment:
75
+ break;
76
+ default:
77
+ break;
78
+ }
79
+
80
+ await subType.destroy();
81
+ }
82
+ }
83
+ // create a hyperlink
84
+ const firstPage = await doc.getPage(1);
85
+ const createURIAction = await PDFNet.Action.createURI(doc, 'http://www.pdftron.com');
86
+ const linkRect = new PDFNet.Rect(85, 570, 503, 524);
87
+ const hyperlink = await PDFNet.LinkAnnot.create(doc, linkRect);
88
+ await hyperlink.setAction(createURIAction);
89
+ await firstPage.annotPushBack(hyperlink);
90
+
91
+ // Create an intra-document link...
92
+ const page3 = await doc.getPage(3);
93
+ const gotoPage3 = await PDFNet.Action.createGoto(await PDFNet.Destination.createFitH(page3, 0));
94
+ const link = await PDFNet.LinkAnnot.create(doc, (new PDFNet.Rect(85, 458, 503, 502)));
95
+ await link.setAction(gotoPage3);
96
+ const greenColorPt = await PDFNet.ColorPt.init(0, 0, 1);
97
+ await link.setColor(greenColorPt);
98
+
99
+ // Add the new annotation to the first page
100
+ await firstPage.annotPushBack(link);
101
+
102
+ // Create a stamp annotation ...
103
+ const stamp = await PDFNet.RubberStampAnnot.create(doc, (new PDFNet.Rect(30, 30, 300, 200)));
104
+ await stamp.setIconName('Draft');
105
+ await firstPage.annotPushBack(stamp);
106
+
107
+ // Create a file attachment annotation (embed the 'peppers.jpg').
108
+ const file_attach = await PDFNet.FileAttachmentAnnot.createDefault(doc, (new PDFNet.Rect(80, 280, 108, 320)), inputPath + 'peppers.jpg');
109
+ await firstPage.annotPushBack(file_attach);
110
+
111
+ const ink = await PDFNet.InkAnnot.create(doc, (new PDFNet.Rect(110, 10, 300, 200)));
112
+ const pt3 = new PDFNet.Point(110, 10);
113
+ await ink.setPoint(0, 0, pt3);
114
+ pt3.x = 150;
115
+ pt3.y = 50;
116
+ await ink.setPoint(0, 1, pt3);
117
+ pt3.x = 190;
118
+ pt3.y = 60;
119
+ await ink.setPoint(0, 2, pt3);
120
+ pt3.x = 180;
121
+ pt3.y = 90;
122
+ await ink.setPoint(1, 0, pt3);
123
+ pt3.x = 190;
124
+ pt3.y = 95;
125
+ await ink.setPoint(1, 1, pt3);
126
+ pt3.x = 200;
127
+ pt3.y = 100;
128
+ await ink.setPoint(1, 2, pt3);
129
+ pt3.x = 166;
130
+ pt3.y = 86;
131
+ await ink.setPoint(2, 0, pt3);
132
+ pt3.x = 196;
133
+ pt3.y = 96;
134
+ await ink.setPoint(2, 1, pt3);
135
+ pt3.x = 221;
136
+ pt3.y = 121;
137
+ await ink.setPoint(2, 2, pt3);
138
+ pt3.x = 288;
139
+ pt3.y = 188;
140
+ await ink.setPoint(2, 3, pt3);
141
+ const cyanColorPt = await PDFNet.ColorPt.init(0, 1, 1);
142
+ await ink.setColor(cyanColorPt, 3);
143
+ firstPage.annotPushBack(ink);
144
+
145
+ await PDFNet.endDeallocateStack();
146
+ };
147
+
148
+ const AnnotationLowLevelAPI = async(doc) => {
149
+ try {
150
+ await PDFNet.startDeallocateStack(); // start stack-based deallocation. All objects will be deallocated by end of function
151
+ const itr = await doc.getPageIterator();
152
+ const page = await itr.current();
153
+
154
+ let annots = await page.getAnnots();
155
+
156
+ if (annots == null) {
157
+ // If there are no annotations, create a new annotation
158
+ // array for the page.
159
+ annots = await doc.createIndirectArray();
160
+ const sdfDoc = await page.getSDFObj();
161
+ await sdfDoc.put('Annots', annots);
162
+ }
163
+
164
+ // Create a Text annotation
165
+ const annot = await doc.createIndirectDict();
166
+ await annot.putName('Subtype', 'Text');
167
+ await annot.putBool('Open', true);
168
+ await annot.putString('Contents', 'The quick brown fox ate the lazy mouse.');
169
+ await annot.putRect('Rect', 266, 116, 430, 204);
170
+
171
+ // Insert the annotation in the page annotation array
172
+ await annots.pushBack(annot);
173
+
174
+ // Create a Link annotation
175
+ const link1 = await doc.createIndirectDict();
176
+ await link1.putName('Subtype', 'Link');
177
+ const dest = await PDFNet.Destination.createFit((await doc.getPage(2)));
178
+ await link1.put('Dest', (await dest.getSDFObj()));
179
+ await link1.putRect('Rect', 85, 705, 503, 661);
180
+ await annots.pushBack(link1);
181
+
182
+ // Create another Link annotation
183
+ const link2 = await doc.createIndirectDict();
184
+ await link2.putName('Subtype', 'Link');
185
+ const dest2 = await PDFNet.Destination.createFit((await doc.getPage(3)));
186
+ await link2.put('Dest', (await dest2.getSDFObj()));
187
+ await link2.putRect('Rect', 85, 638, 503, 594);
188
+ await annots.pushBack(link2);
189
+
190
+ // link2 = annots.GetAt(annots.Size()-1);
191
+ const tenthPage = await doc.getPage(10);
192
+ // XYZ destination stands for 'left', 'top' and 'zoom' coordinates
193
+ const XYZDestination = await PDFNet.Destination.createXYZ(tenthPage, 100, 722, 10);
194
+ await link2.put('Dest', (await XYZDestination.getSDFObj()));
195
+
196
+ // Create a third link annotation with a hyperlink action (all other
197
+ // annotation types can be created in a similar way)
198
+ const link3 = await doc.createIndirectDict();
199
+ await link3.putName('Subtype', 'Link');
200
+ await link3.putRect('Rect', 85, 570, 503, 524);
201
+
202
+ // Create a URI action
203
+ const action = await link3.putDict('A');
204
+ await action.putName('S', 'URI');
205
+ await action.putString('URI', 'http://www.pdftron.com');
206
+
207
+ await annots.pushBack(link3);
208
+ await PDFNet.endDeallocateStack();
209
+ } catch (err) {
210
+ console.log(err);
211
+ }
212
+ };
213
+
214
+ const CreateTestAnnots = async(doc) => {
215
+ await PDFNet.startDeallocateStack();
216
+ const ew = await PDFNet.ElementWriter.create(); // elementWriter
217
+ const eb = await PDFNet.ElementBuilder.create(); // elementBuilder
218
+ let element;
219
+
220
+ const firstPage = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
221
+ doc.pagePushBack(firstPage);
222
+ ew.beginOnPage(firstPage, PDFNet.ElementWriter.WriteMode.e_overlay, false); // begin writing to this page
223
+ ew.end(); // save changes to the current page
224
+
225
+ // NOTE: The following code represents three different ways to create a text annotation.
226
+ {
227
+ const txtannot = await PDFNet.FreeTextAnnot.create(doc, new PDFNet.Rect(10, 400, 160, 570));
228
+ await txtannot.setContents('\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare.\n\nAha!\n\nAnd there was much rejoicing!');
229
+ const solidLine = await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 1, 10, 20);
230
+ await txtannot.setBorderStyle(solidLine, false);
231
+ await txtannot.setQuaddingFormat(0);
232
+ await firstPage.annotPushBack(txtannot);
233
+ await txtannot.refreshAppearance();
234
+ }
235
+
236
+ {
237
+ const txtannot = await PDFNet.FreeTextAnnot.create(doc, new PDFNet.Rect(100, 100, 350, 500));
238
+ await txtannot.setContentRect(new PDFNet.Rect(200, 200, 350, 500));
239
+ await txtannot.setContents('\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare.\n\nAha!\n\nAnd there was much rejoicing!');
240
+ await txtannot.setCalloutLinePoints(new PDFNet.Point(200, 300), new PDFNet.Point(150, 290), new PDFNet.Point(110, 110));
241
+ const solidLine = await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 1, 10, 20);
242
+ await txtannot.setBorderStyle(solidLine, false);
243
+ await txtannot.setEndingStyle(PDFNet.LineAnnot.EndingStyle.e_ClosedArrow);
244
+ const greenColorPt = await PDFNet.ColorPt.init(0, 1, 0);
245
+ await txtannot.setColorDefault(greenColorPt); // default value of last param is 0
246
+ await txtannot.setQuaddingFormat(1);
247
+ await firstPage.annotPushBack(txtannot);
248
+ await txtannot.refreshAppearance();
249
+ }
250
+ {
251
+ const txtannot = await PDFNet.FreeTextAnnot.create(doc, new PDFNet.Rect(400, 10, 550, 400));
252
+ await txtannot.setContents('\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare.\n\nAha!\n\nAnd there was much rejoicing!');
253
+ const solidLine = await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 1, 10, 20);
254
+ await txtannot.setBorderStyle(solidLine, false);
255
+ const redColorPt = await PDFNet.ColorPt.init(0, 0, 1);
256
+ await txtannot.setColorDefault(redColorPt);
257
+ await txtannot.setOpacity(0.2);
258
+ await txtannot.setQuaddingFormat(2);
259
+ await firstPage.annotPushBack(txtannot);
260
+ await txtannot.refreshAppearance();
261
+ }
262
+ const page = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
263
+ doc.pagePushBack(page);
264
+ await ew.beginOnPage(page, PDFNet.ElementWriter.WriteMode.e_overlay, false);
265
+ await eb.reset();
266
+ await ew.end(); // save changes to the current page
267
+ {
268
+ // Create a Line annotation...
269
+ const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(250, 250, 400, 400));
270
+ await line.setStartPoint(new PDFNet.Point(350, 270));
271
+ await line.setEndPoint(new PDFNet.Point(260, 370));
272
+ await line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Square);
273
+ await line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
274
+ const darkGreenColorPt = await PDFNet.ColorPt.init(0.3, 0.5, 0);
275
+ await line.setColor(darkGreenColorPt, 3);
276
+ await line.setContents('Dashed Captioned');
277
+ await line.setShowCaption(true);
278
+ await line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
279
+ const dash = [2.0, 2.0];
280
+ const bStyle = await PDFNet.AnnotBorderStyle.createWithDashPattern(PDFNet.AnnotBorderStyle.Style.e_dashed, 2, 0, 0, dash);
281
+ line.setBorderStyle(bStyle);
282
+ line.refreshAppearance();
283
+ page.annotPushBack(line);
284
+ }
285
+ {
286
+ const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(347, 377, 600, 600));
287
+ await line.setStartPoint(new PDFNet.Point(385, 410));
288
+ await line.setEndPoint(new PDFNet.Point(540, 555));
289
+ await line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
290
+ await line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_OpenArrow);
291
+ const redColorPt = await PDFNet.ColorPt.init(1, 0, 0);
292
+ await line.setColor(redColorPt, 3);
293
+ const greenColorPt = await PDFNet.ColorPt.init(0, 1, 0);
294
+ await line.setInteriorColor(greenColorPt, 3);
295
+ await line.setContents('Inline Caption');
296
+ await line.setShowCaption(true);
297
+ await line.setCapPos(PDFNet.LineAnnot.CapPos.e_Inline);
298
+ await line.setLeaderLineExtensionLength(-4.0);
299
+ await line.setLeaderLineLength(-12);
300
+ await line.setLeaderLineOffset(2.0);
301
+ await line.refreshAppearance();
302
+ page.annotPushBack(line);
303
+ }
304
+ {
305
+ const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(10, 400, 200, 600));
306
+ await line.setStartPoint(new PDFNet.Point(25, 426));
307
+ await line.setEndPoint(new PDFNet.Point(180, 555));
308
+ await line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
309
+ await line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_Square);
310
+ const blueColorPt = await PDFNet.ColorPt.init(0, 0, 1);
311
+ await line.setColor(blueColorPt, 3);
312
+ const redColorPt = await PDFNet.ColorPt.init(1, 0, 0);
313
+ await line.setInteriorColor(redColorPt, 3);
314
+ await line.setContents('Offset Caption');
315
+ await line.setShowCaption(true);
316
+ await line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
317
+ await line.setTextHOffset(-60);
318
+ await line.setTextVOffset(10);
319
+ await line.refreshAppearance();
320
+ page.annotPushBack(line);
321
+ }
322
+ {
323
+ const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(200, 10, 400, 70));
324
+ line.setStartPoint(new PDFNet.Point(220, 25));
325
+ line.setEndPoint(new PDFNet.Point(370, 60));
326
+ line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Butt);
327
+ line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_OpenArrow);
328
+ line.setColor((await PDFNet.ColorPt.init(0, 0, 1)), 3);
329
+ line.setContents('Regular Caption');
330
+ line.setShowCaption(true);
331
+ line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
332
+ await line.refreshAppearance();
333
+ page.annotPushBack(line);
334
+ }
335
+ {
336
+ const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(200, 70, 400, 130));
337
+ line.setStartPoint(new PDFNet.Point(220, 111));
338
+ line.setEndPoint(new PDFNet.Point(370, 78));
339
+ line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
340
+ line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_Diamond);
341
+ line.setContents('Circle to Diamond');
342
+ line.setColor((await PDFNet.ColorPt.init(0, 0, 1)), 3);
343
+ line.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
344
+ line.setShowCaption(true);
345
+ line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
346
+ line.refreshAppearance();
347
+ page.annotPushBack(line);
348
+ }
349
+ {
350
+ const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(10, 100, 160, 200));
351
+ line.setStartPoint(new PDFNet.Point(15, 110));
352
+ line.setEndPoint(new PDFNet.Point(150, 190));
353
+ line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Slash);
354
+ line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_ClosedArrow);
355
+ line.setContents('Slash to CArrow');
356
+ line.setColor((await PDFNet.ColorPt.init(1, 0, 0)), 3);
357
+ line.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 1)), 3);
358
+ line.setShowCaption(true);
359
+ line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
360
+ line.refreshAppearance();
361
+ page.annotPushBack(line);
362
+ }
363
+ {
364
+ const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(270, 270, 570, 433));
365
+ line.setStartPoint(new PDFNet.Point(300, 400));
366
+ line.setEndPoint(new PDFNet.Point(550, 300));
367
+ line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_RClosedArrow);
368
+ line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_ROpenArrow);
369
+ line.setContents('ROpen & RClosed arrows');
370
+ line.setColor((await PDFNet.ColorPt.init(0, 0, 1)), 3);
371
+ line.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
372
+ line.setShowCaption(true);
373
+ line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
374
+ line.refreshAppearance();
375
+ page.annotPushBack(line);
376
+ }
377
+ {
378
+ const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(195, 395, 205, 505));
379
+ line.setStartPoint(new PDFNet.Point(200, 400));
380
+ line.setEndPoint(new PDFNet.Point(200, 500));
381
+ line.refreshAppearance();
382
+ page.annotPushBack(line);
383
+ }
384
+ {
385
+ const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(55, 299, 150, 301));
386
+ line.setStartPoint(new PDFNet.Point(55, 300));
387
+ line.setEndPoint(new PDFNet.Point(155, 300));
388
+ line.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
389
+ line.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_Circle);
390
+ line.setContents(("Caption that's longer than its line."));
391
+ line.setColor((await PDFNet.ColorPt.init(1, 0, 1)), 3);
392
+ line.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
393
+ line.setShowCaption(true);
394
+ line.setCapPos(PDFNet.LineAnnot.CapPos.e_Top);
395
+ line.refreshAppearance();
396
+ page.annotPushBack(line);
397
+ }
398
+ {
399
+ const line = await PDFNet.LineAnnot.create(doc, new PDFNet.Rect(300, 200, 390, 234));
400
+ line.setStartPoint(new PDFNet.Point(310, 210));
401
+ line.setEndPoint(new PDFNet.Point(380, 220));
402
+ line.setColor((await PDFNet.ColorPt.init(0, 0, 0)), 3);
403
+ line.refreshAppearance();
404
+ page.annotPushBack(line);
405
+ }
406
+ const page3 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
407
+ ew.beginOnPage(page3); // begin writing to the page
408
+ ew.end(); // save changes to the current page
409
+ doc.pagePushBack(page3);
410
+ {
411
+ const circle = await PDFNet.CircleAnnot.create(doc, new PDFNet.Rect(300, 300, 390, 350));
412
+ circle.setColor((await PDFNet.ColorPt.init(0, 0, 0)), 3);
413
+ circle.refreshAppearance();
414
+ page3.annotPushBack(circle);
415
+ }
416
+ {
417
+ const circle = await PDFNet.CircleAnnot.create(doc, new PDFNet.Rect(100, 100, 200, 200));
418
+ circle.setColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
419
+ circle.setInteriorColor((await PDFNet.ColorPt.init(0, 0, 1)), 3);
420
+ const dash = [2, 4];
421
+ circle.setBorderStyle((await PDFNet.AnnotBorderStyle.createWithDashPattern(PDFNet.AnnotBorderStyle.Style.e_dashed, 3, 0, 0, dash)));
422
+ circle.setPadding(new PDFNet.Rect(2, 2, 2, 2));
423
+ circle.refreshAppearance();
424
+ page3.annotPushBack(circle);
425
+ }
426
+ {
427
+ const sq = await PDFNet.SquareAnnot.create(doc, new PDFNet.Rect(10, 200, 80, 300));
428
+ sq.setColor((await PDFNet.ColorPt.init(0, 0, 0)), 3);
429
+ sq.refreshAppearance();
430
+ page3.annotPushBack(sq);
431
+ }
432
+
433
+ {
434
+ const sq = await PDFNet.SquareAnnot.create(doc, new PDFNet.Rect(500, 200, 580, 300));
435
+ sq.setColor((await PDFNet.ColorPt.init(1, 0, 0)), 3);
436
+ sq.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 1)), 3);
437
+ const dash = [4, 2];
438
+ sq.setBorderStyle((await PDFNet.AnnotBorderStyle.createWithDashPattern(PDFNet.AnnotBorderStyle.Style.e_dashed, 6, 0, 0, dash)));
439
+ sq.setPadding(new PDFNet.Rect(4, 4, 4, 4));
440
+ sq.refreshAppearance();
441
+ page3.annotPushBack(sq);
442
+ }
443
+
444
+ {
445
+ const poly = await PDFNet.PolygonAnnot.create(doc, new PDFNet.Rect(5, 500, 125, 590));
446
+ poly.setColor((await PDFNet.ColorPt.init(1, 0, 0)), 3);
447
+ poly.setInteriorColor((await PDFNet.ColorPt.init(1, 1, 0)), 3);
448
+ poly.setVertex(0, new PDFNet.Point(12, 510));
449
+ poly.setVertex(1, new PDFNet.Point(100, 510));
450
+ poly.setVertex(2, new PDFNet.Point(100, 555));
451
+ poly.setVertex(3, new PDFNet.Point(35, 544));
452
+ const solidBorderStyle = await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 4, 0, 0);
453
+ poly.setBorderStyle(solidBorderStyle);
454
+ poly.setPadding(new PDFNet.Rect(4, 4, 4, 4));
455
+ poly.refreshAppearance();
456
+ page3.annotPushBack(poly);
457
+ }
458
+ {
459
+ const poly = await PDFNet.PolyLineAnnot.create(doc, new PDFNet.Rect(400, 10, 500, 90));
460
+ poly.setColor((await PDFNet.ColorPt.init(1, 0, 0)), 3);
461
+ poly.setInteriorColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
462
+ poly.setVertex(0, new PDFNet.Point(405, 20));
463
+ poly.setVertex(1, new PDFNet.Point(440, 40));
464
+ poly.setVertex(2, new PDFNet.Point(410, 60));
465
+ poly.setVertex(3, new PDFNet.Point(470, 80));
466
+ poly.setBorderStyle(await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 2, 0, 0));
467
+ poly.setPadding(new PDFNet.Rect(4, 4, 4, 4));
468
+ poly.setStartStyle(PDFNet.LineAnnot.EndingStyle.e_RClosedArrow);
469
+ poly.setEndStyle(PDFNet.LineAnnot.EndingStyle.e_ClosedArrow);
470
+ poly.refreshAppearance();
471
+ page3.annotPushBack(poly);
472
+ }
473
+ {
474
+ const lk = await PDFNet.LinkAnnot.create(doc, new PDFNet.Rect(5, 5, 55, 24));
475
+ // lk.setColor(await PDFNet.ColorPt.init(0,1,0), 3 );
476
+ lk.refreshAppearance();
477
+ page3.annotPushBack(lk);
478
+ }
479
+
480
+ const page4 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
481
+ ew.beginOnPage(page4); // begin writing to the page
482
+ ew.end(); // save changes to the current page
483
+ doc.pagePushBack(page4);
484
+
485
+ {
486
+ ew.beginOnPage(page4);
487
+ const font = await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_helvetica);
488
+ element = await eb.createTextBeginWithFont(font, 16);
489
+ element.setPathFill(true);
490
+ ew.writeElement(element);
491
+ element = await eb.createTextRun('Some random text on the page', font, 16);
492
+ element.setTextMatrixEntries(1, 0, 0, 1, 100, 500);
493
+ ew.writeElement(element);
494
+ ew.writeElement((await eb.createTextEnd()));
495
+ ew.end();
496
+ }
497
+ {
498
+ const hl = await PDFNet.HighlightAnnot.create(doc, new PDFNet.Rect(100, 490, 150, 515));
499
+ hl.setColor((await PDFNet.ColorPt.init(0, 1, 0)), 3);
500
+ hl.refreshAppearance();
501
+ page4.annotPushBack(hl);
502
+ }
503
+ {
504
+ const sq = await PDFNet.SquigglyAnnot.create(doc, new PDFNet.Rect(100, 450, 250, 600));
505
+ // sq.setColor(await PDFNet.ColorPt.init(1,0,0), 3 );
506
+ sq.setQuadPoint(0, new PDFNet.QuadPoint(122, 455, 240, 545, 230, 595, 101, 500));
507
+ sq.refreshAppearance();
508
+ page4.annotPushBack(sq);
509
+ }
510
+ {
511
+ const cr = await PDFNet.CaretAnnot.create(doc, new PDFNet.Rect(100, 40, 129, 69));
512
+ cr.setColor((await PDFNet.ColorPt.init(0, 0, 1)), 3);
513
+ cr.setSymbol('P');
514
+ cr.refreshAppearance();
515
+ page4.annotPushBack(cr);
516
+ }
517
+
518
+
519
+ const page5 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
520
+ ew.beginOnPage(page5); // begin writing to the page
521
+ ew.end(); // save changes to the current page
522
+ doc.pagePushBack(page5);
523
+ const fs = await PDFNet.FileSpec.create(doc, inputPath + 'butterfly.png', false);
524
+ const page6 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
525
+ ew.beginOnPage(page6); // begin writing to the page
526
+ ew.end(); // save changes to the current page
527
+ doc.pagePushBack(page6);
528
+
529
+ {
530
+ const txt = await PDFNet.TextAnnot.create(doc, new PDFNet.Rect(10, 20, 30, 40));
531
+ txt.setIconName('UserIcon');
532
+ txt.setContents('User defined icon, unrecognized by appearance generator');
533
+ txt.setColor((await PDFNet.ColorPt.init(0, 1, 0)));
534
+ txt.refreshAppearance();
535
+ page6.annotPushBack(txt);
536
+ }
537
+ {
538
+ const ink = await PDFNet.InkAnnot.create(doc, new PDFNet.Rect(100, 400, 200, 550));
539
+ ink.setColor((await PDFNet.ColorPt.init(0, 0, 1)));
540
+ ink.setPoint(1, 3, new PDFNet.Point(220, 505));
541
+ ink.setPoint(1, 0, new PDFNet.Point(100, 490));
542
+ ink.setPoint(0, 1, new PDFNet.Point(120, 410));
543
+ ink.setPoint(0, 0, new PDFNet.Point(100, 400));
544
+ ink.setPoint(1, 2, new PDFNet.Point(180, 490));
545
+ ink.setPoint(1, 1, new PDFNet.Point(140, 440));
546
+ ink.setBorderStyle(await PDFNet.AnnotBorderStyle.create(PDFNet.AnnotBorderStyle.Style.e_solid, 3, 0, 0));
547
+ ink.refreshAppearance();
548
+ page6.annotPushBack(ink);
549
+ }
550
+
551
+
552
+ const page7 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
553
+ ew.beginOnPage(page7); // begin writing to the page
554
+ ew.end(); // save changes to the current page
555
+ doc.pagePushBack(page7);
556
+
557
+ {
558
+ const snd = await PDFNet.SoundAnnot.create(doc, new PDFNet.Rect(100, 500, 120, 520));
559
+ snd.setColor((await PDFNet.ColorPt.init(1, 1, 0)));
560
+ snd.setIcon(PDFNet.SoundAnnot.Icon.e_Speaker);
561
+ snd.refreshAppearance();
562
+ page7.annotPushBack(snd);
563
+ }
564
+ {
565
+ const snd = await PDFNet.SoundAnnot.create(doc, new PDFNet.Rect(200, 500, 220, 520));
566
+ snd.setColor((await PDFNet.ColorPt.init(1, 1, 0)));
567
+ snd.setIcon(PDFNet.SoundAnnot.Icon.e_Mic);
568
+ snd.refreshAppearance();
569
+ page7.annotPushBack(snd);
570
+ }
571
+
572
+ const page8 = await doc.pageCreate(new PDFNet.Rect(0, 0, 600, 600));
573
+ ew.beginOnPage(page8); // begin writing to the page
574
+ ew.end(); // save changes to the current page
575
+ doc.pagePushBack(page8);
576
+
577
+ for (let ipage = 0; ipage < 2; ++ipage) {
578
+ let px = 5;
579
+ let py = 520;
580
+ for (let istamp = PDFNet.RubberStampAnnot.Icon.e_Approved; istamp <= PDFNet.RubberStampAnnot.Icon.e_Draft; istamp++) {
581
+ const st = await PDFNet.RubberStampAnnot.create(doc, new PDFNet.Rect(1, 1, 100, 100));
582
+ st.setIcon(istamp);
583
+ st.setContents((await st.getIconName()));
584
+ st.setRect(new PDFNet.Rect(px, py, px + 100, py + 25));
585
+ py -= 100;
586
+ if (py < 0) {
587
+ py = 520;
588
+ px += 200;
589
+ }
590
+ if (ipage === 0) {
591
+ // page7.annotPushBack( st );
592
+ } else {
593
+ page8.annotPushBack(st);
594
+ st.refreshAppearance();
595
+ }
596
+ }
597
+ }
598
+ const st = await PDFNet.RubberStampAnnot.create(doc, new PDFNet.Rect(400, 5, 550, 45));
599
+ st.setIconName('UserStamp');
600
+ st.setContents('User defined stamp');
601
+ page8.annotPushBack(st);
602
+ st.refreshAppearance();
603
+
604
+ await PDFNet.endDeallocateStack();
605
+ };
606
+
607
+ const main = async() => {
608
+ try {
609
+ const ret = 0;
610
+
611
+ const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'numbered.pdf');
612
+ doc.initSecurityHandler();
613
+
614
+
615
+ await AnnotationLowLevelAPI(doc);
616
+ await doc.save(inputPath + 'Output/annotation_test1.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
617
+
618
+ console.log('Done. Results saved in annotation_test1.pdf');
619
+
620
+ // eslint-disable-next-line no-unused-vars
621
+ const firstPage = await doc.getPage(1);
622
+
623
+ await AnnotationHighLevelAPI(doc);
624
+ await doc.save(inputPath + 'Output/annotation_test2.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
625
+ console.log('Done. Results saved in annotation_test2.pdf');
626
+
627
+ // creating various annotations in a brand new document
628
+ const docnew = await PDFNet.PDFDoc.create();
629
+ await CreateTestAnnots(docnew);
630
+ await docnew.save(inputPath + 'Output/new_annot_test_api.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
631
+ console.log('Saved new_annot_test_api.pdf');
632
+ return ret;
633
+ } catch (err) {
634
+ console.log(err);
635
+ }
636
+ };
637
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
638
+ };
639
+ exports.runAnnotationTest();
640
+ })(exports);
641
+ // eslint-disable-next-line spaced-comment
642
642
  //# sourceURL=AnnotationTest.js