@pdftron/pdfnet-node-samples 9.4.2 → 9.5.0-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/package.json +18 -18
  2. package/readme.md +12 -12
  3. package/samples/runall.bat +12 -12
  4. package/samples/AddImageTest/AddImageTest.js +0 -116
  5. package/samples/AdvancedImagingTest/AdvancedImagingTest.js +0 -78
  6. package/samples/AnnotationTest/AnnotationTest.js +0 -642
  7. package/samples/BookmarkTest/BookmarkTest.js +0 -220
  8. package/samples/CAD2PDFTest/CAD2PDFTest.js +0 -80
  9. package/samples/ContentReplacerTest/ContentReplacerTest.js +0 -75
  10. package/samples/ConvertTest/ConvertTest.js +0 -256
  11. package/samples/DigitalSignaturesTest/DigitalSignaturesTest.js +0 -527
  12. package/samples/ElementBuilderTest/ElementBuilderTest.js +0 -514
  13. package/samples/ElementEditTest/ElementEditTest.js +0 -111
  14. package/samples/ElementReaderAdvTest/ElementReaderAdvTest.js +0 -305
  15. package/samples/ElementReaderTest/ElementReaderTest.js +0 -77
  16. package/samples/EncTest/EncTest.js +0 -176
  17. package/samples/FDFTest/FDFTest.js +0 -219
  18. package/samples/HTML2PDFTest/HTML2PDFTest.js +0 -166
  19. package/samples/HighlightsTest/HighlightsTest.js +0 -97
  20. package/samples/ImageExtractTest/ImageExtractTest.js +0 -130
  21. package/samples/ImpositionTest/ImpositionTest.js +0 -87
  22. package/samples/InteractiveFormsTest/InteractiveFormsTest.js +0 -382
  23. package/samples/JBIG2Test/JBIG2Test.js +0 -89
  24. package/samples/LicenseKey/LicenseKey.js +0 -11
  25. package/samples/LogicalStructureTest/LogicalStructureTest.js +0 -251
  26. package/samples/OCRTest/OCRTest.js +0 -235
  27. package/samples/OfficeTemplateTest/OfficeTemplateTest.js +0 -77
  28. package/samples/OfficeToPDFTest/OfficeToPDFTest.js +0 -125
  29. package/samples/OptimizerTest/OptimizerTest.js +0 -192
  30. package/samples/PDF2HtmlTest/PDF2HtmlTest.js +0 -123
  31. package/samples/PDF2OfficeTest/PDF2OfficeTest.js +0 -158
  32. package/samples/PDFATest/PDFATest.js +0 -85
  33. package/samples/PDFDocMemoryTest/PDFDocMemoryTest.js +0 -85
  34. package/samples/PDFDrawTest/PDFDrawTest.js +0 -306
  35. package/samples/PDFLayersTest/PDFLayersTest.js +0 -295
  36. package/samples/PDFPackageTest/PDFPackageTest.js +0 -112
  37. package/samples/PDFPageTest/PDFPageTest.js +0 -190
  38. package/samples/PDFRedactTest/PDFRedactTest.js +0 -75
  39. package/samples/PageLabelsTest/PageLabelsTest.js +0 -139
  40. package/samples/PatternTest/PatternTest.js +0 -227
  41. package/samples/RectTest/RectTest.js +0 -41
  42. package/samples/SDFTest/SDFTest.js +0 -89
  43. package/samples/StamperTest/StamperTest.js +0 -256
  44. package/samples/TestFiles/BusinessCardTemplate.pdf +0 -0
  45. package/samples/TestFiles/Fishermen.docx +0 -0
  46. package/samples/TestFiles/Font_licenses.txt +0 -140
  47. package/samples/TestFiles/GlobalSignRootForTST.cer +0 -0
  48. package/samples/TestFiles/License.txt +0 -1
  49. package/samples/TestFiles/Misc-Fixed.pfa +0 -1166
  50. package/samples/TestFiles/NotoSans_with_hindi.ttf +0 -0
  51. package/samples/TestFiles/Output/empty +0 -1
  52. package/samples/TestFiles/SHA-2 Root USERTrust RSA CA Sectigo timestamping.crt +0 -34
  53. package/samples/TestFiles/SYH_Letter.docx +0 -0
  54. package/samples/TestFiles/TigerText.pdf +0 -0
  55. package/samples/TestFiles/US061222892-a.pdf +0 -0
  56. package/samples/TestFiles/butterfly.png +0 -0
  57. package/samples/TestFiles/credit card numbers.pdf +0 -0
  58. package/samples/TestFiles/dice.jpg +0 -0
  59. package/samples/TestFiles/dice.u3d +0 -0
  60. package/samples/TestFiles/doc_to_sign.pdf +0 -0
  61. package/samples/TestFiles/factsheet_Arabic.docx +0 -0
  62. package/samples/TestFiles/fish.pdf +0 -0
  63. package/samples/TestFiles/font.ttf +0 -0
  64. package/samples/TestFiles/form1.pdf +1 -245
  65. package/samples/TestFiles/form1_annots.xfdf +0 -34
  66. package/samples/TestFiles/form1_data.fdf +0 -4
  67. package/samples/TestFiles/form1_data.xfdf +0 -140
  68. package/samples/TestFiles/grayscale.tif +0 -0
  69. package/samples/TestFiles/hindi_sample_utf16le.txt +0 -0
  70. package/samples/TestFiles/imagemask.dat +0 -32
  71. package/samples/TestFiles/logo_red.png +0 -0
  72. package/samples/TestFiles/lorem_ipsum.pdf +0 -0
  73. package/samples/TestFiles/multipage.tif +0 -0
  74. package/samples/TestFiles/my_stream.txt +0 -2310
  75. package/samples/TestFiles/newsletter.pdf +0 -0
  76. package/samples/TestFiles/newsletter.xod +0 -0
  77. package/samples/TestFiles/numbered.pdf +0 -0
  78. package/samples/TestFiles/op_blend_test.pdf +0 -1498
  79. package/samples/TestFiles/palm.jp2 +0 -0
  80. package/samples/TestFiles/paragraphs_and_tables.pdf +0 -0
  81. package/samples/TestFiles/pdfnet.gif +0 -0
  82. package/samples/TestFiles/pdftron.bmp +0 -0
  83. package/samples/TestFiles/pdftron.cer +0 -0
  84. package/samples/TestFiles/pdftron.pfx +0 -0
  85. package/samples/TestFiles/pdftron_smart_substitution.plugin +0 -0
  86. package/samples/TestFiles/peppers.jpg +0 -0
  87. package/samples/TestFiles/signature.jpg +0 -0
  88. package/samples/TestFiles/simple-emf.emf +0 -0
  89. package/samples/TestFiles/simple-excel_2007.xlsx +0 -0
  90. package/samples/TestFiles/simple-outlook.msg +0 -0
  91. package/samples/TestFiles/simple-powerpoint_2007.pptx +0 -0
  92. package/samples/TestFiles/simple-publisher.pub +0 -0
  93. package/samples/TestFiles/simple-rtf.rtf +0 -224
  94. package/samples/TestFiles/simple-text.txt +0 -61
  95. package/samples/TestFiles/simple-visio.vsd +0 -0
  96. package/samples/TestFiles/simple-webpage.html +0 -731
  97. package/samples/TestFiles/simple-webpage.mht +0 -6972
  98. package/samples/TestFiles/simple-webpage_files/colorschememapping.xml +0 -2
  99. package/samples/TestFiles/simple-webpage_files/filelist.xml +0 -14
  100. package/samples/TestFiles/simple-webpage_files/image001.gif +0 -0
  101. package/samples/TestFiles/simple-webpage_files/image002.png +0 -0
  102. package/samples/TestFiles/simple-webpage_files/image003.jpg +0 -0
  103. package/samples/TestFiles/simple-webpage_files/image004.emz +0 -0
  104. package/samples/TestFiles/simple-webpage_files/image005.gif +0 -0
  105. package/samples/TestFiles/simple-webpage_files/image006.png +0 -0
  106. package/samples/TestFiles/simple-webpage_files/image007.gif +0 -0
  107. package/samples/TestFiles/simple-webpage_files/oledata.mso +0 -0
  108. package/samples/TestFiles/simple-webpage_files/themedata.thmx +0 -0
  109. package/samples/TestFiles/simple-word_2007.docx +0 -0
  110. package/samples/TestFiles/simple-xps.xps +0 -0
  111. package/samples/TestFiles/tagged.pdf +0 -0
  112. package/samples/TestFiles/the_rime_of_the_ancient_mariner.docx +0 -0
  113. package/samples/TestFiles/tiger.pdf +0 -0
  114. package/samples/TestFiles/waiver.pdf +0 -0
  115. package/samples/TestFiles/waiver_withApprovalField.pdf +0 -0
  116. package/samples/TestFiles/waiver_withApprovalField_certified.pdf +1 -424
  117. package/samples/TestFiles/waiver_withApprovalField_certified_approved.pdf +1 -466
  118. package/samples/TextExtractTest/TextExtractTest.js +0 -287
  119. package/samples/TextSearchTest/TextSearchTest.js +0 -122
  120. package/samples/U3DTest/U3DTest.js +0 -105
  121. package/samples/UndoRedoTest/UndoRedoTest.js +0 -101
  122. package/samples/UnicodeWriteTest/UnicodeWriteTest.js +0 -174
  123. package/samples/WebViewerConvertTest/WebViewerConvertTest.js +0 -136
@@ -1,87 +0,0 @@
1
- //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2022 by PDFTron Systems Inc. All Rights Reserved.
3
- // Consult legal.txt regarding legal and license information.
4
- //---------------------------------------------------------------------------------------
5
-
6
- //-----------------------------------------------------------------------------------
7
- // The sample illustrates how multiple pages can be combined/imposed
8
- // using PDFNet. Page imposition can be used to arrange/order pages
9
- // prior to printing or to assemble a 'master' page from several 'source'
10
- // pages. Using PDFNet API it is possible to write applications that can
11
- // re-order the pages such that they will display in the correct order
12
- // when the hard copy pages are compiled and folded correctly.
13
- //-----------------------------------------------------------------------------------
14
-
15
- const { PDFNet } = require('@pdftron/pdfnet-node');
16
- const PDFTronLicense = require('../LicenseKey/LicenseKey');
17
-
18
- ((exports) => {
19
- 'use strict';
20
-
21
- exports.runImpositionTest = () => {
22
- const main = async () => {
23
- try {
24
- console.log('-------------------------------------------------');
25
- console.log('Opening the input pdf...');
26
- const in_doc = await PDFNet.PDFDoc.createFromFilePath('../TestFiles/newsletter.pdf');
27
- in_doc.initSecurityHandler();
28
-
29
- // Create a list of pages to import from one PDF document to another.
30
- const import_pages = [];
31
- for (let itr = await in_doc.getPageIterator(); await itr.hasNext(); await itr.next()) {
32
- import_pages.push(await itr.current());
33
- }
34
-
35
- const new_doc = await PDFNet.PDFDoc.create();
36
- const imported_pages = await new_doc.importPages(import_pages);
37
-
38
- // Paper dimension for A3 format in points. Because one inch has
39
- // 72 points, 11.69 inch 72 = 841.69 points
40
- const media_box = await PDFNet.Rect.init(0, 0, 1190.88, 841.69);
41
- const mid_point = await media_box.width() / 2;
42
- const builder = await PDFNet.ElementBuilder.create();
43
- const writer = await PDFNet.ElementWriter.create();
44
- for (let i = 0; i < imported_pages.length; ++i) {
45
- // Create a blank new A3 page and place on it two pages from the input document.
46
- const new_page = await new_doc.pageCreate(media_box);
47
- writer.beginOnPage(new_page);
48
- // Place the first page
49
- let src_page = imported_pages[i];
50
- var element = await builder.createFormFromPage(src_page);
51
-
52
- let sc_x = mid_point / await src_page.getPageWidth();
53
- let sc_y = await media_box.height() / await src_page.getPageHeight();
54
- let scale = sc_x < sc_y ? sc_x : sc_y; // min(sc_x, sc_y)
55
- await element.getGState().then(gstate => gstate.setTransform(scale, 0, 0, scale, 0, 0));
56
- writer.writePlacedElement(element);
57
-
58
- // Place the second page
59
- ++i;
60
- if (i < imported_pages.length) {
61
- src_page = imported_pages[i];
62
- element = await builder.createFormFromPage(src_page);
63
- sc_x = mid_point / await src_page.getPageWidth();
64
- sc_y = await media_box.height() / await src_page.getPageHeight();
65
- scale = sc_x < sc_y ? sc_x : sc_y; // min(sc_x, sc_y)
66
- await element.getGState().then(gstate => gstate.setTransform(scale, 0, 0, scale, mid_point, 0));
67
- writer.writePlacedElement(element);
68
- }
69
-
70
- await writer.end();
71
- new_doc.pagePushBack(new_page);
72
- }
73
- await new_doc.save('../TestFiles/Output/newsletter_booklet.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
74
- console.log('Done. Result saved in newsletter_booklet.pdf...');
75
-
76
- } catch (err) {
77
- console.log(err);
78
- }
79
- }
80
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
81
- console.log('Error: ' + JSON.stringify(error));
82
- }).then(function(){ return PDFNet.shutdown(); });
83
- };
84
- exports.runImpositionTest();
85
- })(exports);
86
- // eslint-disable-next-line spaced-comment
87
- //# sourceURL=ImpositionTest.js
@@ -1,382 +0,0 @@
1
- //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2022 by PDFTron Systems 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
- //# sourceURL=InteractiveFormsTest.js
@@ -1,89 +0,0 @@
1
- //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2022 by PDFTron Systems Inc. All Rights Reserved.
3
- // Consult legal.txt regarding legal and license information.
4
- //---------------------------------------------------------------------------------------
5
-
6
-
7
- // This sample project illustrates how to recompress bi-tonal images in an
8
- // existing PDF document using JBIG2 compression. The sample is not intended
9
- // to be a generic PDF optimization tool.
10
- //
11
- // You can download the entire document using the following link:
12
- // http://www.pdftron.com/net/samplecode/data/US061222892.pdf
13
- //
14
-
15
- const { PDFNet } = require('@pdftron/pdfnet-node');
16
- const PDFTronLicense = require('../LicenseKey/LicenseKey');
17
-
18
- ((exports) => {
19
- 'use strict';
20
-
21
- exports.runJBIG2Test = () => {
22
- const main = async () => {
23
- try {
24
- const pdf_doc = await PDFNet.PDFDoc.createFromFilePath('../TestFiles/US061222892-a.pdf');
25
- pdf_doc.initSecurityHandler();
26
-
27
- const cos_doc = await pdf_doc.getSDFDoc();
28
- const num_objs = await cos_doc.xRefSize();
29
- for (let i = 1; i < num_objs; ++i) {
30
- const obj = await cos_doc.getObj(i);
31
- if (obj && !(await obj.isFree()) && await obj.isStream()) {
32
- // Process only images
33
- let itr = await obj.find('Subtype');
34
- if (!(await itr.hasNext()) || await (await itr.value()).getName() !== 'Image')
35
- continue;
36
- const input_image = await PDFNet.Image.createFromObj(obj);
37
- // Process only gray-scale images
38
- if (await input_image.getComponentNum() != 1)
39
- continue;
40
- if (await input_image.getBitsPerComponent() != 1) // Recompress only 1 BPC images
41
- continue;
42
-
43
- // Skip images that are already compressed using JBIG2
44
- itr = await obj.find('Filter');
45
- if (await itr.hasNext()) {
46
- const value = await itr.value();
47
- if (await value.isName() && await value.getName() === 'JBIG2Decode') continue;
48
- }
49
-
50
- const filter = await obj.getDecodedStream();
51
- const reader = await PDFNet.FilterReader.create(filter);
52
-
53
- const hint_set = await PDFNet.ObjSet.create();
54
- const hint = await hint_set.createArray();
55
-
56
- hint.pushBackName('JBIG2');
57
- hint.pushBackName('Lossless');
58
-
59
- const new_image = await PDFNet.Image.createFromStream(cos_doc, reader, await input_image.getImageWidth(),
60
- await input_image.getImageHeight(), 1, await PDFNet.ColorSpace.createDeviceGray(), hint);
61
-
62
- const new_img_obj = await new_image.getSDFObj();
63
- itr = await obj.find('Decode');
64
- if (await itr.hasNext())
65
- new_img_obj.put('Decode', await itr.value());
66
- itr = await obj.find('ImageMask');
67
- if (await itr.hasNext())
68
- new_img_obj.put('ImageMask', await itr.value());
69
- itr = await obj.find('Mask');
70
- if (await itr.hasNext())
71
- new_img_obj.put('Mask', await itr.value());
72
-
73
- await cos_doc.swap(i, await new_img_obj.getObjNum());
74
- }
75
- }
76
-
77
- pdf_doc.save('../TestFiles/Output/US061222892_JBIG2.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
78
- } catch (err) {
79
- console.log(err);
80
- }
81
- };
82
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
83
- console.log('Error: ' + JSON.stringify(error));
84
- }).then(function(){ return PDFNet.shutdown(); });
85
- };
86
- exports.runJBIG2Test();
87
- })(exports);
88
- // eslint-disable-next-line spaced-comment
89
- //# sourceURL=JBIG2Test.js
@@ -1,11 +0,0 @@
1
- //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3
- // Consult legal.txt regarding legal and license information.
4
- //---------------------------------------------------------------------------------------
5
-
6
- //"Enter your key here. If you don't have it, please go to https://www.pdftron.com/pws/get-key to obtain a demo license or https://www.pdftron.com/form/contact-sales to obtain a production key.
7
- const LicenseKey = 'YOUR_PDFTRON_LICENSE_KEY';
8
- if(LicenseKey == 'YOUR_PDFTRON_LICENSE_KEY'){
9
- throw ('Please enter your license key by replacing \'YOUR_PDFTRON_LICENSE_KEY\' that is assigned to the LicenseKey variable in Samples/LicenseKey/LicenseKey.js. If you do not have a license key, please go to https://www.pdftron.com/pws/get-key to obtain a demo license or https://www.pdftron.com/form/contact-sales to obtain a production key.');
10
- }
11
- exports.Key = LicenseKey;