@pdftron/pdfnet-node-samples 10.9.0 → 10.10.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 (135) hide show
  1. package/{samples/AddImageTest → AddImageTest}/AddImageTest.js +115 -115
  2. package/{samples/AdvancedImagingTest → AdvancedImagingTest}/AdvancedImagingTest.js +78 -78
  3. package/{samples/AnnotationTest → AnnotationTest}/AnnotationTest.js +641 -641
  4. package/{samples/BookmarkTest → BookmarkTest}/BookmarkTest.js +219 -219
  5. package/{samples/CAD2PDFTest → CAD2PDFTest}/CAD2PDFTest.js +79 -79
  6. package/{samples/ContentReplacerTest → ContentReplacerTest}/ContentReplacerTest.js +75 -75
  7. package/{samples/ConvertPrintTest → ConvertPrintTest}/ConvertPrintTest.js +153 -153
  8. package/{samples/ConvertTest → ConvertTest}/ConvertTest.js +203 -203
  9. package/{samples/DataExtractionTest → DataExtractionTest}/DataExtractionTest.js +214 -214
  10. package/{samples/DigitalSignaturesTest → DigitalSignaturesTest}/DigitalSignaturesTest.js +622 -527
  11. package/{samples/DocumentCreationTest → DocumentCreationTest}/DocumentCreationTest.js +409 -409
  12. package/{samples/ElementBuilderTest → ElementBuilderTest}/ElementBuilderTest.js +513 -513
  13. package/{samples/ElementEditTest → ElementEditTest}/ElementEditTest.js +110 -110
  14. package/{samples/ElementReaderAdvTest → ElementReaderAdvTest}/ElementReaderAdvTest.js +305 -305
  15. package/{samples/ElementReaderTest → ElementReaderTest}/ElementReaderTest.js +77 -77
  16. package/{samples/EncTest → EncTest}/EncTest.js +175 -175
  17. package/{samples/FDFTest → FDFTest}/FDFTest.js +218 -218
  18. package/{samples/HTML2PDFTest → HTML2PDFTest}/HTML2PDFTest.js +164 -164
  19. package/{samples/HighlightsTest → HighlightsTest}/HighlightsTest.js +97 -97
  20. package/{samples/ImageExtractTest → ImageExtractTest}/ImageExtractTest.js +129 -129
  21. package/{samples/ImpositionTest → ImpositionTest}/ImpositionTest.js +86 -86
  22. package/{samples/InteractiveFormsTest → InteractiveFormsTest}/InteractiveFormsTest.js +381 -381
  23. package/{samples/JBIG2Test → JBIG2Test}/JBIG2Test.js +88 -88
  24. package/{samples/LicenseKey → LicenseKey}/LicenseKey.js +11 -11
  25. package/{samples/LogicalStructureTest → LogicalStructureTest}/LogicalStructureTest.js +250 -250
  26. package/{samples/OCRTest → OCRTest}/OCRTest.js +235 -235
  27. package/{samples/OfficeTemplateTest → OfficeTemplateTest}/OfficeTemplateTest.js +79 -79
  28. package/{samples/OfficeToPDFTest → OfficeToPDFTest}/OfficeToPDFTest.js +125 -125
  29. package/{samples/OptimizerTest → OptimizerTest}/OptimizerTest.js +191 -191
  30. package/{samples/PDF2HtmlTest → PDF2HtmlTest}/PDF2HtmlTest.js +123 -123
  31. package/{samples/PDF2OfficeTest → PDF2OfficeTest}/PDF2OfficeTest.js +158 -158
  32. package/{samples/PDFATest → PDFATest}/PDFATest.js +85 -85
  33. package/{samples/PDFDocMemoryTest → PDFDocMemoryTest}/PDFDocMemoryTest.js +84 -84
  34. package/{samples/PDFDrawTest → PDFDrawTest}/PDFDrawTest.js +305 -305
  35. package/{samples/PDFLayersTest → PDFLayersTest}/PDFLayersTest.js +294 -294
  36. package/{samples/PDFPackageTest → PDFPackageTest}/PDFPackageTest.js +111 -111
  37. package/{samples/PDFPageTest → PDFPageTest}/PDFPageTest.js +189 -189
  38. package/{samples/PDFRedactTest → PDFRedactTest}/PDFRedactTest.js +74 -74
  39. package/{samples/PageLabelsTest → PageLabelsTest}/PageLabelsTest.js +138 -138
  40. package/{samples/PatternTest → PatternTest}/PatternTest.js +226 -226
  41. package/{samples/RectTest → RectTest}/RectTest.js +40 -40
  42. package/{samples/SDFTest → SDFTest}/SDFTest.js +87 -87
  43. package/{samples/StamperTest → StamperTest}/StamperTest.js +255 -255
  44. package/{samples/TestFiles → TestFiles}/Misc-Fixed.pfa +1166 -1166
  45. package/{samples/TestFiles → TestFiles}/SHA-2 Root USERTrust RSA CA Sectigo timestamping.crt +34 -34
  46. package/{samples/TestFiles → TestFiles}/form1_annots.xfdf +33 -33
  47. package/{samples/TestFiles → TestFiles}/form1_data.xfdf +139 -139
  48. package/{samples/TestFiles → TestFiles}/my_stream.txt +2310 -2310
  49. package/{samples/TestFiles → TestFiles}/tiger.svg +378 -378
  50. package/{samples/TextExtractTest → TextExtractTest}/TextExtractTest.js +286 -286
  51. package/{samples/TextSearchTest → TextSearchTest}/TextSearchTest.js +121 -121
  52. package/{samples/U3DTest → U3DTest}/U3DTest.js +104 -104
  53. package/{samples/UndoRedoTest → UndoRedoTest}/UndoRedoTest.js +101 -101
  54. package/{samples/UnicodeWriteTest → UnicodeWriteTest}/UnicodeWriteTest.js +173 -173
  55. package/{samples/WebViewerConvertTest → WebViewerConvertTest}/WebViewerConvertTest.js +135 -135
  56. package/legal.txt +632 -0
  57. package/license.pdf +0 -0
  58. package/package.json +20 -21
  59. package/readme.md +38 -13
  60. package/{samples/runall.bat → runall.bat} +12 -12
  61. package/{samples/runall.sh → runall.sh} +15 -15
  62. /package/{samples/TestFiles → TestFiles}/BusinessCardTemplate.pdf +0 -0
  63. /package/{samples/TestFiles → TestFiles}/Fishermen.docx +0 -0
  64. /package/{samples/TestFiles → TestFiles}/Font_licenses.txt +0 -0
  65. /package/{samples/TestFiles → TestFiles}/GlobalSignRootForTST.cer +0 -0
  66. /package/{samples/TestFiles → TestFiles}/License.txt +0 -0
  67. /package/{samples/TestFiles → TestFiles}/NotoSans_with_hindi.ttf +0 -0
  68. /package/{samples/TestFiles → TestFiles}/Output/empty +0 -0
  69. /package/{samples/TestFiles → TestFiles}/SYH_Letter.docx +0 -0
  70. /package/{samples/TestFiles → TestFiles}/TigerText.pdf +0 -0
  71. /package/{samples/TestFiles → TestFiles}/US061222892-a.pdf +0 -0
  72. /package/{samples/TestFiles → TestFiles}/butterfly.png +0 -0
  73. /package/{samples/TestFiles → TestFiles}/credit card numbers.pdf +0 -0
  74. /package/{samples/TestFiles → TestFiles}/dice.jpg +0 -0
  75. /package/{samples/TestFiles → TestFiles}/dice.u3d +0 -0
  76. /package/{samples/TestFiles → TestFiles}/doc_to_sign.pdf +0 -0
  77. /package/{samples/TestFiles → TestFiles}/factsheet_Arabic.docx +0 -0
  78. /package/{samples/TestFiles → TestFiles}/financial.pdf +0 -0
  79. /package/{samples/TestFiles → TestFiles}/fish.pdf +0 -0
  80. /package/{samples/TestFiles → TestFiles}/font.ttf +0 -0
  81. /package/{samples/TestFiles → TestFiles}/form1.pdf +0 -0
  82. /package/{samples/TestFiles → TestFiles}/form1_data.fdf +0 -0
  83. /package/{samples/TestFiles → TestFiles}/formfields-scanned-withfields.pdf +0 -0
  84. /package/{samples/TestFiles → TestFiles}/formfields-scanned.pdf +0 -0
  85. /package/{samples/TestFiles → TestFiles}/formfields.pdf +0 -0
  86. /package/{samples/TestFiles → TestFiles}/grayscale.tif +0 -0
  87. /package/{samples/TestFiles → TestFiles}/hindi_sample_utf16le.txt +0 -0
  88. /package/{samples/TestFiles → TestFiles}/imagemask.dat +0 -0
  89. /package/{samples/TestFiles → TestFiles}/logo_red.png +0 -0
  90. /package/{samples/TestFiles → TestFiles}/lorem_ipsum.pdf +0 -0
  91. /package/{samples/TestFiles → TestFiles}/multipage.tif +0 -0
  92. /package/{samples/TestFiles → TestFiles}/newsletter.pdf +0 -0
  93. /package/{samples/TestFiles → TestFiles}/newsletter.xod +0 -0
  94. /package/{samples/TestFiles → TestFiles}/numbered.pdf +0 -0
  95. /package/{samples/TestFiles → TestFiles}/op_blend_test.pdf +0 -0
  96. /package/{samples/TestFiles → TestFiles}/palm.jp2 +0 -0
  97. /package/{samples/TestFiles → TestFiles}/paragraphs_and_tables.pdf +0 -0
  98. /package/{samples/TestFiles → TestFiles}/pdfnet.gif +0 -0
  99. /package/{samples/TestFiles → TestFiles}/pdftron.bmp +0 -0
  100. /package/{samples/TestFiles → TestFiles}/pdftron.cer +0 -0
  101. /package/{samples/TestFiles → TestFiles}/pdftron.pfx +0 -0
  102. /package/{samples/TestFiles → TestFiles}/pdftron_smart_substitution.plugin +0 -0
  103. /package/{samples/TestFiles → TestFiles}/peppers.jpg +0 -0
  104. /package/{samples/TestFiles → TestFiles}/signature.jpg +0 -0
  105. /package/{samples/TestFiles → TestFiles}/simple-emf.emf +0 -0
  106. /package/{samples/TestFiles → TestFiles}/simple-excel_2007.xlsx +0 -0
  107. /package/{samples/TestFiles → TestFiles}/simple-outlook.msg +0 -0
  108. /package/{samples/TestFiles → TestFiles}/simple-powerpoint_2007.pptx +0 -0
  109. /package/{samples/TestFiles → TestFiles}/simple-publisher.pub +0 -0
  110. /package/{samples/TestFiles → TestFiles}/simple-rtf.rtf +0 -0
  111. /package/{samples/TestFiles → TestFiles}/simple-text.txt +0 -0
  112. /package/{samples/TestFiles → TestFiles}/simple-visio.vsd +0 -0
  113. /package/{samples/TestFiles → TestFiles}/simple-webpage.html +0 -0
  114. /package/{samples/TestFiles → TestFiles}/simple-webpage.mht +0 -0
  115. /package/{samples/TestFiles → TestFiles}/simple-webpage_files/colorschememapping.xml +0 -0
  116. /package/{samples/TestFiles → TestFiles}/simple-webpage_files/filelist.xml +0 -0
  117. /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image001.gif +0 -0
  118. /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image002.png +0 -0
  119. /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image003.jpg +0 -0
  120. /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image004.emz +0 -0
  121. /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image005.gif +0 -0
  122. /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image006.png +0 -0
  123. /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image007.gif +0 -0
  124. /package/{samples/TestFiles → TestFiles}/simple-webpage_files/oledata.mso +0 -0
  125. /package/{samples/TestFiles → TestFiles}/simple-webpage_files/themedata.thmx +0 -0
  126. /package/{samples/TestFiles → TestFiles}/simple-word_2007.docx +0 -0
  127. /package/{samples/TestFiles → TestFiles}/simple-xps.xps +0 -0
  128. /package/{samples/TestFiles → TestFiles}/table.pdf +0 -0
  129. /package/{samples/TestFiles → TestFiles}/tagged.pdf +0 -0
  130. /package/{samples/TestFiles → TestFiles}/the_rime_of_the_ancient_mariner.docx +0 -0
  131. /package/{samples/TestFiles → TestFiles}/tiger.pdf +0 -0
  132. /package/{samples/TestFiles → TestFiles}/waiver.pdf +0 -0
  133. /package/{samples/TestFiles → TestFiles}/waiver_withApprovalField.pdf +0 -0
  134. /package/{samples/TestFiles → TestFiles}/waiver_withApprovalField_certified.pdf +0 -0
  135. /package/{samples/TestFiles → TestFiles}/waiver_withApprovalField_certified_approved.pdf +0 -0
@@ -1,382 +1,382 @@
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
- // This sample illustrates basic PDFNet capabilities related to interactive
8
- // forms (also known as AcroForms).
9
- //---------------------------------------------------------------------------------------
10
- const { PDFNet } = require('@pdftron/pdfnet-node');
11
- const PDFTronLicense = require('../LicenseKey/LicenseKey');
12
-
13
- ((exports) => {
14
- 'use strict';
15
-
16
- exports.runInteractiveFormsTest = () => {
17
-
18
- // field_nums has to be greater than 0.
19
- const RenameAllFields = async (doc, name, field_nums = 1) => {
20
- let itr = await doc.getFieldIterator(name);
21
- for (let counter = 0; (await itr.hasNext()); itr = (await doc.getFieldIterator(name)), ++counter) {
22
- const f = await itr.current();
23
- const update_count = Math.ceil(counter / field_nums);
24
- f.rename(name + update_count);
25
- }
26
- };
27
-
28
- const CreateCustomButtonAppearance = async (doc, buttonDown) => {
29
- // Create a button appearance stream ------------------------------------
30
-
31
- const builder = await PDFNet.ElementBuilder.create();
32
- const writer = await PDFNet.ElementWriter.create();
33
- writer.begin(doc);
34
-
35
- // Draw background
36
- let element = await builder.createRect(0, 0, 101, 37);
37
- element.setPathFill(true);
38
- element.setPathStroke(false);
39
-
40
- let elementGState = await element.getGState();
41
- elementGState.setFillColorSpace(await PDFNet.ColorSpace.createDeviceGray());
42
- elementGState.setFillColorWithColorPt(await PDFNet.ColorPt.init(0.75));
43
- writer.writeElement(element);
44
-
45
- // Draw 'Submit' text
46
- writer.writeElement((await builder.createTextBegin()));
47
-
48
- const text = 'Submit';
49
- const helveticaBoldFont = await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_helvetica_bold);
50
- element = await builder.createTextRun(text, helveticaBoldFont, 12);
51
- elementGState = await element.getGState();
52
- elementGState.setFillColorWithColorPt((await PDFNet.ColorPt.init(0)));
53
-
54
- if (buttonDown) {
55
- element.setTextMatrixEntries(1, 0, 0, 1, 33, 10);
56
- } else {
57
- element.setTextMatrixEntries(1, 0, 0, 1, 30, 13);
58
- }
59
- writer.writeElement(element);
60
-
61
- writer.writeElement((await builder.createTextEnd()));
62
-
63
- const stm = await writer.end();
64
-
65
- // Set the bounding box
66
- await stm.putRect('BBox', 0, 0, 101, 37);
67
- await stm.putName('Subtype', 'Form');
68
- return stm;
69
- };
70
-
71
- const main = async () => {
72
- const outputPath = '../TestFiles/Output/';
73
-
74
- //----------------------------------------------------------------------------------
75
- // Example 1: Programatically create new Form Fields and Widget Annotations.
76
- //----------------------------------------------------------------------------------
77
- try {
78
- const doc = await PDFNet.PDFDoc.create();
79
- doc.initSecurityHandler();
80
-
81
- // Create a blank new page and add some form fields.
82
- const blankPage = await doc.pageCreate();
83
-
84
- // Text Widget Creation
85
- // Create an empty text widget with black text..
86
- const text1 = await PDFNet.TextWidget.create(doc, await PDFNet.Rect.init(110, 700, 380, 730));
87
- text1.setText('Basic Text Field');
88
- await text1.refreshAppearance();
89
- blankPage.annotPushBack(text1);
90
- // Create a vertical text widget with blue text and a yellow background.
91
- const text2 = await PDFNet.TextWidget.create(doc, await PDFNet.Rect.init(50, 400, 90, 730));
92
- text2.setRotation(90);
93
- // Set the text content.
94
- text2.setText(' ****Lucky Stars!****');
95
- // Set the font type, text color, font size, border color and background color.
96
- text2.setFont(await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_helvetica_oblique));
97
- text2.setFontSize(28);
98
- text2.setTextColor(await PDFNet.ColorPt.init(0, 0, 1), 3);
99
- text2.setBorderColor(await PDFNet.ColorPt.init(0, 0, 0), 3);
100
- text2.setBackgroundColor(await PDFNet.ColorPt.init(1, 1, 0), 3);
101
- await text2.refreshAppearance();
102
- // Add the annotation to the page.
103
- blankPage.annotPushBack(text2);
104
- // Create two new text widget with Field names employee.name.first and employee.name.last
105
- // This logic shows how these widgets can be created using either a field name string or
106
- // a Field object
107
- const text3 = await PDFNet.TextWidget.create(doc, await PDFNet.Rect.init(110, 660, 380, 690), 'employee.name.first');
108
- text3.setText('Levi');
109
- text3.setFont(await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_times_bold));
110
- await text3.refreshAppearance();
111
- blankPage.annotPushBack(text3);
112
- const empLastName = await doc.fieldCreateFromStrings('employee.name.last', PDFNet.Field.Type.e_text, 'Ackerman');
113
- const text4 = await PDFNet.TextWidget.createWithField(doc, await PDFNet.Rect.init(110, 620, 380, 650), empLastName);
114
- text4.setFont(await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_times_bold));
115
- await text4.refreshAppearance();
116
- blankPage.annotPushBack(text4);
117
-
118
- // Signature Widget Creation (unsigned)
119
- const signature1 = await PDFNet.SignatureWidget.create(doc, await PDFNet.Rect.init(110, 560, 260, 610));
120
- await signature1.refreshAppearance();
121
- blankPage.annotPushBack(signature1);
122
-
123
- // CheckBox Widget Creation
124
- // Create a check box widget that is not checked.
125
- const check1 = await PDFNet.CheckBoxWidget.create(doc, await PDFNet.Rect.init(140, 490, 170, 520));
126
- await check1.refreshAppearance();
127
- blankPage.annotPushBack(check1);
128
- // Create a check box widget that is checked.
129
- const check2 = await PDFNet.CheckBoxWidget.create(doc, await PDFNet.Rect.init(190, 490, 250, 540), 'employee.name.check1');
130
- check2.setBackgroundColor(await PDFNet.ColorPt.init(1, 1, 1), 3);
131
- check2.setBorderColor(await PDFNet.ColorPt.init(0, 0, 0), 3);
132
- // Check the widget (by default it is unchecked).
133
- check2.setChecked(true);
134
- await check2.refreshAppearance();
135
- blankPage.annotPushBack(check2);
136
-
137
- // PushButton Widget Creation
138
- const pushbutton1 = await PDFNet.PushButtonWidget.create(doc, await PDFNet.Rect.init(380, 490, 520, 540));
139
- pushbutton1.setTextColor(await PDFNet.ColorPt.init(1, 1, 1), 3);
140
- pushbutton1.setFontSize(36);
141
- pushbutton1.setBackgroundColor(await PDFNet.ColorPt.init(0, 0, 0), 3);
142
- // Add a caption for the pushbutton.
143
- pushbutton1.setStaticCaptionText('PushButton');
144
- await pushbutton1.refreshAppearance();
145
- blankPage.annotPushBack(pushbutton1);
146
-
147
- // ComboBox Widget Creation
148
- const combo1 = await PDFNet.ComboBoxWidget.create(doc, await PDFNet.Rect.init(280, 560, 580, 610));
149
- // Add options to the combobox widget.
150
- combo1.addOption('Combo Box No.1');
151
- combo1.addOption('Combo Box No.2');
152
- combo1.addOption('Combo Box No.3');
153
- // Make one of the options in the combo box selected by default.
154
- combo1.setSelectedOption('Combo Box No.2');
155
- combo1.setTextColor(await PDFNet.ColorPt.init(1, 0, 0), 3);
156
- combo1.setFontSize(28);
157
- await combo1.refreshAppearance();
158
- blankPage.annotPushBack(combo1);
159
-
160
- // ListBox Widget Creation
161
- const list1 = await PDFNet.ListBoxWidget.create(doc, await PDFNet.Rect.init(400, 620, 580, 730));
162
- // Add one option to the listbox widget.
163
- list1.addOption('List Box No.1');
164
- // Add multiple options to the listbox widget in a batch.
165
- const list_options = ['List Box No.2', 'List Box No.3'];
166
- list1.addOptions(list_options);
167
- // Select some of the options in list box as default options
168
- list1.setSelectedOptions(list_options);
169
- // Enable list box to have multi-select when editing.
170
- await (await list1.getField()).setFlag(PDFNet.Field.Flag.e_multiselect, true);
171
- list1.setFont(await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_times_italic));
172
- list1.setTextColor(await PDFNet.ColorPt.init(1, 0, 0), 3);
173
- list1.setFontSize(28);
174
- list1.setBackgroundColor(await PDFNet.ColorPt.init(1, 1, 1), 3);
175
- await list1.refreshAppearance();
176
- await blankPage.annotPushBack(list1);
177
-
178
- // RadioButton Widget Creation
179
- // Create a radio button group and add three radio buttons in it.
180
- const radio_group = await PDFNet.RadioButtonGroup.create(doc, 'RadioGroup');
181
- const radiobutton1 = await radio_group.add(await PDFNet.Rect.init(140, 410, 190, 460));
182
- radiobutton1.setBackgroundColor(await PDFNet.ColorPt.init(1, 1, 0), 3);
183
- await radiobutton1.refreshAppearance();
184
- const radiobutton2 = await radio_group.add(await PDFNet.Rect.init(310, 410, 360, 460));
185
- radiobutton2.setBackgroundColor(await PDFNet.ColorPt.init(0, 1, 0), 3);
186
- await radiobutton2.refreshAppearance();
187
- const radiobutton3 = await radio_group.add(await PDFNet.Rect.init(480, 410, 530, 460));
188
- // Enable the third radio button. By default the first one is selected
189
- radiobutton3.enableButton();
190
- radiobutton3.setBackgroundColor(await PDFNet.ColorPt.init(0, 1, 1), 3);
191
- await radiobutton3.refreshAppearance();
192
- await radio_group.addGroupButtonsToPage(blankPage);
193
-
194
- // Custom push button annotation creation
195
- const custom_pushbutton1 = await PDFNet.PushButtonWidget.create(doc, await PDFNet.Rect.init(260, 320, 360, 360));
196
- // Set the annotation appearance.
197
- custom_pushbutton1.setAppearance(await CreateCustomButtonAppearance(doc, false), PDFNet.Annot.State.e_normal);
198
- // Create 'SubmitForm' action. The action will be linked to the button.
199
- const url = await PDFNet.FileSpec.createURL(doc, 'http://www.pdftron.com');
200
- const button_action = await PDFNet.Action.createSubmitForm(url);
201
- // Associate the above action with 'Down' event in annotations action dictionary.
202
- const annot_action = await (await custom_pushbutton1.getSDFObj()).putDict('AA');
203
- await annot_action.put('D', await button_action.getSDFObj());
204
- await blankPage.annotPushBack(custom_pushbutton1);
205
-
206
- // Add the page as the last page in the document.
207
- doc.pagePushBack(blankPage);
208
- // If you are not satisfied with the look of default auto-generated appearance
209
- // streams you can delete "AP" entry from the Widget annotation and set
210
- // "NeedAppearances" flag in AcroForm dictionary:
211
- // doc.GetAcroForm().PutBool("NeedAppearances", true);
212
- // This will force the viewer application to auto-generate new appearance streams
213
- // every time the document is opened.
214
- //
215
- // Alternatively you can generate custom annotation appearance using ElementWriter
216
- // and then set the "AP" entry in the widget dictionary to the new appearance
217
- // stream.
218
- //
219
- // Yet another option is to pre-populate field entries with dummy text. When
220
- // you edit the field values using PDFNet the new field appearances will match
221
- // the old ones.
222
-
223
- //doc.GetAcroForm().PutBool("NeedAppearances", true);
224
- // NOTE: RefreshFieldAppearances will replace previously generated appearance streams
225
-
226
- doc.refreshFieldAppearances();
227
-
228
- await doc.save(outputPath + 'forms_test1.pdf', 0);
229
-
230
- console.log('Done.');
231
- } catch (err) {
232
- console.log(err.stack);
233
- }
234
-
235
- //----------------------------------------------------------------------------------
236
- // Example 2:
237
- // Fill-in forms / Modify values of existing fields.
238
- // Traverse all form fields in the document (and print out their names).
239
- // Search for specific fields in the document.
240
- //----------------------------------------------------------------------------------
241
-
242
- // This is used later on to clone the fields
243
- const field_names = {};
244
- try {
245
- const doc = await PDFNet.PDFDoc.createFromFilePath(outputPath + 'forms_test1.pdf');
246
- doc.initSecurityHandler();
247
-
248
- const itr = await doc.getFieldIteratorBegin();
249
- for (; (await itr.hasNext()); itr.next()) {
250
- const currentItr = await itr.current();
251
- const curFieldName = await currentItr.getName();
252
-
253
- // Add one to the count for this field name for later processing
254
- field_names[curFieldName] = (curFieldName in field_names ? field_names[curFieldName] + 1 : 1);
255
-
256
- console.log('Field name: ' + curFieldName);
257
- console.log('Field partial name: ' + (await currentItr.getPartialName()));
258
-
259
- const typeStr = 'Field type: ';
260
- const type = await currentItr.getType();
261
- const strVal = await currentItr.getValueAsString();
262
-
263
- switch (type) {
264
- case PDFNet.Field.Type.e_button:
265
- console.log(typeStr + 'Button');
266
- break;
267
- case PDFNet.Field.Type.e_radio:
268
- console.log(typeStr + 'Radio button: Value = ' + strVal);
269
- break;
270
- case PDFNet.Field.Type.e_check:
271
- currentItr.setValueAsBool(true);
272
- console.log(typeStr + 'Check box: Value = ' + strVal);
273
- break;
274
- case PDFNet.Field.Type.e_text:
275
- console.log(typeStr + 'Text');
276
- // Edit all variable text in the document
277
- currentItr.setValueAsString('This is a new value. The old one was: ' + strVal);
278
- break;
279
- case PDFNet.Field.Type.e_choice:
280
- console.log(typeStr + 'Choice');
281
- break;
282
- case PDFNet.Field.Type.e_signature:
283
- console.log(typeStr + 'Signature');
284
- break;
285
- }
286
- console.log('------------------------------');
287
- }
288
- const f = await doc.getField('employee.name.first');
289
- if (f) {
290
- console.log('Field search for ' + (await f.getName()) + ' was successful');
291
- } else {
292
- console.log('Field search failed');
293
- }
294
- // Regenerate field appearances.
295
- doc.refreshFieldAppearances();
296
-
297
- await doc.save(outputPath + 'forms_test_edit.pdf', 0);
298
- console.log('Done.');
299
- } catch (err) {
300
- console.log(err);
301
- }
302
- //----------------------------------------------------------------------------------
303
- // Sample 3: Form templating
304
- // Replicate pages and form data within a document. Then rename field names to make
305
- // them unique.
306
- //----------------------------------------------------------------------------------
307
- try {
308
- const doc = await PDFNet.PDFDoc.createFromFilePath(outputPath + 'forms_test1.pdf');
309
- doc.initSecurityHandler();
310
-
311
- const srcPage = await doc.getPage(1);
312
- doc.pagePushBack(srcPage); // Append several copies of the first page
313
- doc.pagePushBack(srcPage); // Note that forms are successfully copied
314
- doc.pagePushBack(srcPage);
315
- doc.pagePushBack(srcPage);
316
-
317
- // Now we rename fields in order to make every field unique.
318
- // You can use this technique for dynamic template filling where you have a 'master'
319
- // form page that should be replicated, but with unique field names on every page.
320
- for (const fieldName in field_names) {
321
- await RenameAllFields(doc, fieldName, field_names[fieldName]);
322
- }
323
-
324
- await doc.save(outputPath + 'forms_test1_cloned.pdf', 0);
325
- console.log('Done.');
326
- } catch (err) {
327
- console.log(err);
328
- }
329
-
330
- //----------------------------------------------------------------------------------
331
- // Sample:
332
- // Flatten all form fields in a document.
333
- // Note that this sample is intended to show that it is possible to flatten
334
- // individual fields. PDFNet provides a utility function PDFDoc.FlattenAnnotations()
335
- // that will automatically flatten all fields.
336
- //----------------------------------------------------------------------------------
337
-
338
- try {
339
- const doc = await PDFNet.PDFDoc.createFromFilePath(outputPath + 'forms_test1.pdf');
340
- doc.initSecurityHandler();
341
-
342
- // Flatten all pages
343
- // eslint-disable-next-line no-constant-condition
344
- if (true) {
345
- doc.flattenAnnotations();
346
- } else {
347
- // Manual flattening
348
- for (let pitr = await doc.getPageIterator(); (await pitr.hasNext()); (await pitr.next())) {
349
- const page = await pitr.current();
350
- const annots = await page.getAnnots();
351
-
352
- if (annots) { // Look for all widget annotations (in reverse order)
353
- for (let i = parseInt(await annots.size(), 10) - 1; i >= 0; --i) {
354
- const annotObj = await annots.getAt(i);
355
- const annotObjSubtype = await annotObj.get('Subtype');
356
- // eslint-disable-next-line no-unused-vars
357
- const annotObjVal = await annotObjSubtype.value();
358
- const annotObjName = await annotObjVal.getName();
359
-
360
- if (annotObjName === 'Widget') {
361
- const field = await PDFNet.Field.create(annotObj);
362
- field.flatten(page);
363
- }
364
- }
365
- }
366
- }
367
- }
368
-
369
- await doc.save(outputPath + 'forms_test1_flattened.pdf', 0);
370
- console.log('Done.');
371
- } catch (err) {
372
- console.log(err);
373
- }
374
- };
375
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
376
- console.log('Error: ' + JSON.stringify(error));
377
- }).then(function () { return PDFNet.shutdown(); });
378
- };
379
- exports.runInteractiveFormsTest();
380
- })(exports);
381
- // 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
+ // This sample illustrates basic PDFNet capabilities related to interactive
8
+ // forms (also known as AcroForms).
9
+ //---------------------------------------------------------------------------------------
10
+ const { PDFNet } = require('@pdftron/pdfnet-node');
11
+ const PDFTronLicense = require('../LicenseKey/LicenseKey');
12
+
13
+ ((exports) => {
14
+ 'use strict';
15
+
16
+ exports.runInteractiveFormsTest = () => {
17
+
18
+ // field_nums has to be greater than 0.
19
+ const RenameAllFields = async (doc, name, field_nums = 1) => {
20
+ let itr = await doc.getFieldIterator(name);
21
+ for (let counter = 0; (await itr.hasNext()); itr = (await doc.getFieldIterator(name)), ++counter) {
22
+ const f = await itr.current();
23
+ const update_count = Math.ceil(counter / field_nums);
24
+ f.rename(name + update_count);
25
+ }
26
+ };
27
+
28
+ const CreateCustomButtonAppearance = async (doc, buttonDown) => {
29
+ // Create a button appearance stream ------------------------------------
30
+
31
+ const builder = await PDFNet.ElementBuilder.create();
32
+ const writer = await PDFNet.ElementWriter.create();
33
+ writer.begin(doc);
34
+
35
+ // Draw background
36
+ let element = await builder.createRect(0, 0, 101, 37);
37
+ element.setPathFill(true);
38
+ element.setPathStroke(false);
39
+
40
+ let elementGState = await element.getGState();
41
+ elementGState.setFillColorSpace(await PDFNet.ColorSpace.createDeviceGray());
42
+ elementGState.setFillColorWithColorPt(await PDFNet.ColorPt.init(0.75));
43
+ writer.writeElement(element);
44
+
45
+ // Draw 'Submit' text
46
+ writer.writeElement((await builder.createTextBegin()));
47
+
48
+ const text = 'Submit';
49
+ const helveticaBoldFont = await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_helvetica_bold);
50
+ element = await builder.createTextRun(text, helveticaBoldFont, 12);
51
+ elementGState = await element.getGState();
52
+ elementGState.setFillColorWithColorPt((await PDFNet.ColorPt.init(0)));
53
+
54
+ if (buttonDown) {
55
+ element.setTextMatrixEntries(1, 0, 0, 1, 33, 10);
56
+ } else {
57
+ element.setTextMatrixEntries(1, 0, 0, 1, 30, 13);
58
+ }
59
+ writer.writeElement(element);
60
+
61
+ writer.writeElement((await builder.createTextEnd()));
62
+
63
+ const stm = await writer.end();
64
+
65
+ // Set the bounding box
66
+ await stm.putRect('BBox', 0, 0, 101, 37);
67
+ await stm.putName('Subtype', 'Form');
68
+ return stm;
69
+ };
70
+
71
+ const main = async () => {
72
+ const outputPath = '../TestFiles/Output/';
73
+
74
+ //----------------------------------------------------------------------------------
75
+ // Example 1: Programatically create new Form Fields and Widget Annotations.
76
+ //----------------------------------------------------------------------------------
77
+ try {
78
+ const doc = await PDFNet.PDFDoc.create();
79
+ doc.initSecurityHandler();
80
+
81
+ // Create a blank new page and add some form fields.
82
+ const blankPage = await doc.pageCreate();
83
+
84
+ // Text Widget Creation
85
+ // Create an empty text widget with black text..
86
+ const text1 = await PDFNet.TextWidget.create(doc, await PDFNet.Rect.init(110, 700, 380, 730));
87
+ text1.setText('Basic Text Field');
88
+ await text1.refreshAppearance();
89
+ blankPage.annotPushBack(text1);
90
+ // Create a vertical text widget with blue text and a yellow background.
91
+ const text2 = await PDFNet.TextWidget.create(doc, await PDFNet.Rect.init(50, 400, 90, 730));
92
+ text2.setRotation(90);
93
+ // Set the text content.
94
+ text2.setText(' ****Lucky Stars!****');
95
+ // Set the font type, text color, font size, border color and background color.
96
+ text2.setFont(await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_helvetica_oblique));
97
+ text2.setFontSize(28);
98
+ text2.setTextColor(await PDFNet.ColorPt.init(0, 0, 1), 3);
99
+ text2.setBorderColor(await PDFNet.ColorPt.init(0, 0, 0), 3);
100
+ text2.setBackgroundColor(await PDFNet.ColorPt.init(1, 1, 0), 3);
101
+ await text2.refreshAppearance();
102
+ // Add the annotation to the page.
103
+ blankPage.annotPushBack(text2);
104
+ // Create two new text widget with Field names employee.name.first and employee.name.last
105
+ // This logic shows how these widgets can be created using either a field name string or
106
+ // a Field object
107
+ const text3 = await PDFNet.TextWidget.create(doc, await PDFNet.Rect.init(110, 660, 380, 690), 'employee.name.first');
108
+ text3.setText('Levi');
109
+ text3.setFont(await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_times_bold));
110
+ await text3.refreshAppearance();
111
+ blankPage.annotPushBack(text3);
112
+ const empLastName = await doc.fieldCreateFromStrings('employee.name.last', PDFNet.Field.Type.e_text, 'Ackerman');
113
+ const text4 = await PDFNet.TextWidget.createWithField(doc, await PDFNet.Rect.init(110, 620, 380, 650), empLastName);
114
+ text4.setFont(await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_times_bold));
115
+ await text4.refreshAppearance();
116
+ blankPage.annotPushBack(text4);
117
+
118
+ // Signature Widget Creation (unsigned)
119
+ const signature1 = await PDFNet.SignatureWidget.create(doc, await PDFNet.Rect.init(110, 560, 260, 610));
120
+ await signature1.refreshAppearance();
121
+ blankPage.annotPushBack(signature1);
122
+
123
+ // CheckBox Widget Creation
124
+ // Create a check box widget that is not checked.
125
+ const check1 = await PDFNet.CheckBoxWidget.create(doc, await PDFNet.Rect.init(140, 490, 170, 520));
126
+ await check1.refreshAppearance();
127
+ blankPage.annotPushBack(check1);
128
+ // Create a check box widget that is checked.
129
+ const check2 = await PDFNet.CheckBoxWidget.create(doc, await PDFNet.Rect.init(190, 490, 250, 540), 'employee.name.check1');
130
+ check2.setBackgroundColor(await PDFNet.ColorPt.init(1, 1, 1), 3);
131
+ check2.setBorderColor(await PDFNet.ColorPt.init(0, 0, 0), 3);
132
+ // Check the widget (by default it is unchecked).
133
+ check2.setChecked(true);
134
+ await check2.refreshAppearance();
135
+ blankPage.annotPushBack(check2);
136
+
137
+ // PushButton Widget Creation
138
+ const pushbutton1 = await PDFNet.PushButtonWidget.create(doc, await PDFNet.Rect.init(380, 490, 520, 540));
139
+ pushbutton1.setTextColor(await PDFNet.ColorPt.init(1, 1, 1), 3);
140
+ pushbutton1.setFontSize(36);
141
+ pushbutton1.setBackgroundColor(await PDFNet.ColorPt.init(0, 0, 0), 3);
142
+ // Add a caption for the pushbutton.
143
+ pushbutton1.setStaticCaptionText('PushButton');
144
+ await pushbutton1.refreshAppearance();
145
+ blankPage.annotPushBack(pushbutton1);
146
+
147
+ // ComboBox Widget Creation
148
+ const combo1 = await PDFNet.ComboBoxWidget.create(doc, await PDFNet.Rect.init(280, 560, 580, 610));
149
+ // Add options to the combobox widget.
150
+ combo1.addOption('Combo Box No.1');
151
+ combo1.addOption('Combo Box No.2');
152
+ combo1.addOption('Combo Box No.3');
153
+ // Make one of the options in the combo box selected by default.
154
+ combo1.setSelectedOption('Combo Box No.2');
155
+ combo1.setTextColor(await PDFNet.ColorPt.init(1, 0, 0), 3);
156
+ combo1.setFontSize(28);
157
+ await combo1.refreshAppearance();
158
+ blankPage.annotPushBack(combo1);
159
+
160
+ // ListBox Widget Creation
161
+ const list1 = await PDFNet.ListBoxWidget.create(doc, await PDFNet.Rect.init(400, 620, 580, 730));
162
+ // Add one option to the listbox widget.
163
+ list1.addOption('List Box No.1');
164
+ // Add multiple options to the listbox widget in a batch.
165
+ const list_options = ['List Box No.2', 'List Box No.3'];
166
+ list1.addOptions(list_options);
167
+ // Select some of the options in list box as default options
168
+ list1.setSelectedOptions(list_options);
169
+ // Enable list box to have multi-select when editing.
170
+ await (await list1.getField()).setFlag(PDFNet.Field.Flag.e_multiselect, true);
171
+ list1.setFont(await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_times_italic));
172
+ list1.setTextColor(await PDFNet.ColorPt.init(1, 0, 0), 3);
173
+ list1.setFontSize(28);
174
+ list1.setBackgroundColor(await PDFNet.ColorPt.init(1, 1, 1), 3);
175
+ await list1.refreshAppearance();
176
+ await blankPage.annotPushBack(list1);
177
+
178
+ // RadioButton Widget Creation
179
+ // Create a radio button group and add three radio buttons in it.
180
+ const radio_group = await PDFNet.RadioButtonGroup.create(doc, 'RadioGroup');
181
+ const radiobutton1 = await radio_group.add(await PDFNet.Rect.init(140, 410, 190, 460));
182
+ radiobutton1.setBackgroundColor(await PDFNet.ColorPt.init(1, 1, 0), 3);
183
+ await radiobutton1.refreshAppearance();
184
+ const radiobutton2 = await radio_group.add(await PDFNet.Rect.init(310, 410, 360, 460));
185
+ radiobutton2.setBackgroundColor(await PDFNet.ColorPt.init(0, 1, 0), 3);
186
+ await radiobutton2.refreshAppearance();
187
+ const radiobutton3 = await radio_group.add(await PDFNet.Rect.init(480, 410, 530, 460));
188
+ // Enable the third radio button. By default the first one is selected
189
+ radiobutton3.enableButton();
190
+ radiobutton3.setBackgroundColor(await PDFNet.ColorPt.init(0, 1, 1), 3);
191
+ await radiobutton3.refreshAppearance();
192
+ await radio_group.addGroupButtonsToPage(blankPage);
193
+
194
+ // Custom push button annotation creation
195
+ const custom_pushbutton1 = await PDFNet.PushButtonWidget.create(doc, await PDFNet.Rect.init(260, 320, 360, 360));
196
+ // Set the annotation appearance.
197
+ custom_pushbutton1.setAppearance(await CreateCustomButtonAppearance(doc, false), PDFNet.Annot.State.e_normal);
198
+ // Create 'SubmitForm' action. The action will be linked to the button.
199
+ const url = await PDFNet.FileSpec.createURL(doc, 'http://www.pdftron.com');
200
+ const button_action = await PDFNet.Action.createSubmitForm(url);
201
+ // Associate the above action with 'Down' event in annotations action dictionary.
202
+ const annot_action = await (await custom_pushbutton1.getSDFObj()).putDict('AA');
203
+ await annot_action.put('D', await button_action.getSDFObj());
204
+ await blankPage.annotPushBack(custom_pushbutton1);
205
+
206
+ // Add the page as the last page in the document.
207
+ doc.pagePushBack(blankPage);
208
+ // If you are not satisfied with the look of default auto-generated appearance
209
+ // streams you can delete "AP" entry from the Widget annotation and set
210
+ // "NeedAppearances" flag in AcroForm dictionary:
211
+ // doc.GetAcroForm().PutBool("NeedAppearances", true);
212
+ // This will force the viewer application to auto-generate new appearance streams
213
+ // every time the document is opened.
214
+ //
215
+ // Alternatively you can generate custom annotation appearance using ElementWriter
216
+ // and then set the "AP" entry in the widget dictionary to the new appearance
217
+ // stream.
218
+ //
219
+ // Yet another option is to pre-populate field entries with dummy text. When
220
+ // you edit the field values using PDFNet the new field appearances will match
221
+ // the old ones.
222
+
223
+ //doc.GetAcroForm().PutBool("NeedAppearances", true);
224
+ // NOTE: RefreshFieldAppearances will replace previously generated appearance streams
225
+
226
+ doc.refreshFieldAppearances();
227
+
228
+ await doc.save(outputPath + 'forms_test1.pdf', 0);
229
+
230
+ console.log('Done.');
231
+ } catch (err) {
232
+ console.log(err.stack);
233
+ }
234
+
235
+ //----------------------------------------------------------------------------------
236
+ // Example 2:
237
+ // Fill-in forms / Modify values of existing fields.
238
+ // Traverse all form fields in the document (and print out their names).
239
+ // Search for specific fields in the document.
240
+ //----------------------------------------------------------------------------------
241
+
242
+ // This is used later on to clone the fields
243
+ const field_names = {};
244
+ try {
245
+ const doc = await PDFNet.PDFDoc.createFromFilePath(outputPath + 'forms_test1.pdf');
246
+ doc.initSecurityHandler();
247
+
248
+ const itr = await doc.getFieldIteratorBegin();
249
+ for (; (await itr.hasNext()); itr.next()) {
250
+ const currentItr = await itr.current();
251
+ const curFieldName = await currentItr.getName();
252
+
253
+ // Add one to the count for this field name for later processing
254
+ field_names[curFieldName] = (curFieldName in field_names ? field_names[curFieldName] + 1 : 1);
255
+
256
+ console.log('Field name: ' + curFieldName);
257
+ console.log('Field partial name: ' + (await currentItr.getPartialName()));
258
+
259
+ const typeStr = 'Field type: ';
260
+ const type = await currentItr.getType();
261
+ const strVal = await currentItr.getValueAsString();
262
+
263
+ switch (type) {
264
+ case PDFNet.Field.Type.e_button:
265
+ console.log(typeStr + 'Button');
266
+ break;
267
+ case PDFNet.Field.Type.e_radio:
268
+ console.log(typeStr + 'Radio button: Value = ' + strVal);
269
+ break;
270
+ case PDFNet.Field.Type.e_check:
271
+ currentItr.setValueAsBool(true);
272
+ console.log(typeStr + 'Check box: Value = ' + strVal);
273
+ break;
274
+ case PDFNet.Field.Type.e_text:
275
+ console.log(typeStr + 'Text');
276
+ // Edit all variable text in the document
277
+ currentItr.setValueAsString('This is a new value. The old one was: ' + strVal);
278
+ break;
279
+ case PDFNet.Field.Type.e_choice:
280
+ console.log(typeStr + 'Choice');
281
+ break;
282
+ case PDFNet.Field.Type.e_signature:
283
+ console.log(typeStr + 'Signature');
284
+ break;
285
+ }
286
+ console.log('------------------------------');
287
+ }
288
+ const f = await doc.getField('employee.name.first');
289
+ if (f) {
290
+ console.log('Field search for ' + (await f.getName()) + ' was successful');
291
+ } else {
292
+ console.log('Field search failed');
293
+ }
294
+ // Regenerate field appearances.
295
+ doc.refreshFieldAppearances();
296
+
297
+ await doc.save(outputPath + 'forms_test_edit.pdf', 0);
298
+ console.log('Done.');
299
+ } catch (err) {
300
+ console.log(err);
301
+ }
302
+ //----------------------------------------------------------------------------------
303
+ // Sample 3: Form templating
304
+ // Replicate pages and form data within a document. Then rename field names to make
305
+ // them unique.
306
+ //----------------------------------------------------------------------------------
307
+ try {
308
+ const doc = await PDFNet.PDFDoc.createFromFilePath(outputPath + 'forms_test1.pdf');
309
+ doc.initSecurityHandler();
310
+
311
+ const srcPage = await doc.getPage(1);
312
+ doc.pagePushBack(srcPage); // Append several copies of the first page
313
+ doc.pagePushBack(srcPage); // Note that forms are successfully copied
314
+ doc.pagePushBack(srcPage);
315
+ doc.pagePushBack(srcPage);
316
+
317
+ // Now we rename fields in order to make every field unique.
318
+ // You can use this technique for dynamic template filling where you have a 'master'
319
+ // form page that should be replicated, but with unique field names on every page.
320
+ for (const fieldName in field_names) {
321
+ await RenameAllFields(doc, fieldName, field_names[fieldName]);
322
+ }
323
+
324
+ await doc.save(outputPath + 'forms_test1_cloned.pdf', 0);
325
+ console.log('Done.');
326
+ } catch (err) {
327
+ console.log(err);
328
+ }
329
+
330
+ //----------------------------------------------------------------------------------
331
+ // Sample:
332
+ // Flatten all form fields in a document.
333
+ // Note that this sample is intended to show that it is possible to flatten
334
+ // individual fields. PDFNet provides a utility function PDFDoc.FlattenAnnotations()
335
+ // that will automatically flatten all fields.
336
+ //----------------------------------------------------------------------------------
337
+
338
+ try {
339
+ const doc = await PDFNet.PDFDoc.createFromFilePath(outputPath + 'forms_test1.pdf');
340
+ doc.initSecurityHandler();
341
+
342
+ // Flatten all pages
343
+ // eslint-disable-next-line no-constant-condition
344
+ if (true) {
345
+ doc.flattenAnnotations();
346
+ } else {
347
+ // Manual flattening
348
+ for (let pitr = await doc.getPageIterator(); (await pitr.hasNext()); (await pitr.next())) {
349
+ const page = await pitr.current();
350
+ const annots = await page.getAnnots();
351
+
352
+ if (annots) { // Look for all widget annotations (in reverse order)
353
+ for (let i = parseInt(await annots.size(), 10) - 1; i >= 0; --i) {
354
+ const annotObj = await annots.getAt(i);
355
+ const annotObjSubtype = await annotObj.get('Subtype');
356
+ // eslint-disable-next-line no-unused-vars
357
+ const annotObjVal = await annotObjSubtype.value();
358
+ const annotObjName = await annotObjVal.getName();
359
+
360
+ if (annotObjName === 'Widget') {
361
+ const field = await PDFNet.Field.create(annotObj);
362
+ field.flatten(page);
363
+ }
364
+ }
365
+ }
366
+ }
367
+ }
368
+
369
+ await doc.save(outputPath + 'forms_test1_flattened.pdf', 0);
370
+ console.log('Done.');
371
+ } catch (err) {
372
+ console.log(err);
373
+ }
374
+ };
375
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
376
+ console.log('Error: ' + JSON.stringify(error));
377
+ }).then(function () { return PDFNet.shutdown(); });
378
+ };
379
+ exports.runInteractiveFormsTest();
380
+ })(exports);
381
+ // eslint-disable-next-line spaced-comment
382
382
  //# sourceURL=InteractiveFormsTest.js