@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,227 +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
- const { PDFNet } = require('@pdftron/pdfnet-node');
7
- const PDFTronLicense = require('../LicenseKey/LicenseKey');
8
-
9
- ((exports) => {
10
- 'use strict';
11
-
12
- exports.runPatternTest = () => {
13
- const createTilingPattern = async (doc) => {
14
- const writer = await PDFNet.ElementWriter.create();
15
- const eb = await PDFNet.ElementBuilder.create();
16
-
17
- // Create a new pattern content stream - a heart. ------------
18
- writer.begin(doc);
19
- eb.pathBegin();
20
- eb.moveTo(0, 0);
21
- eb.curveTo(500, 500, 125, 625, 0, 500);
22
- eb.curveTo(-125, 625, -500, 500, 0, 0);
23
- const heart = await eb.pathEnd();
24
- heart.setPathFill(true);
25
-
26
- // Set heart color to red.
27
- const gstate = await heart.getGState();
28
- gstate.setFillColorSpace(await PDFNet.ColorSpace.createDeviceRGB());
29
- gstate.setStrokeColorWithColorPt(await PDFNet.ColorPt.init(1, 0, 0));
30
- writer.writeElement(heart);
31
-
32
- const patternDict = await writer.end();
33
-
34
- // Initialize pattern dictionary. For details on what each parameter represents please
35
- // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
36
- patternDict.putName('Type', 'Pattern');
37
- patternDict.putNumber('PatternType', 1);
38
-
39
- // TilingType - Constant spacing.
40
- patternDict.putNumber('TilingType', 1);
41
-
42
- // This is a Type1 pattern - A colored tiling pattern.
43
- patternDict.putNumber('PaintType', 1);
44
-
45
- // Set bounding box
46
- patternDict.putRect('BBox', -253, 0, 253, 545);
47
-
48
- // Create and set the matrix
49
- const pattern_mtx = await PDFNet.Matrix2D.create(0.04, 0, 0, 0.04, 0, 0);
50
- patternDict.putMatrix('Matrix', pattern_mtx);
51
-
52
- // Set the desired horizontal and vertical spacing between pattern cells,
53
- // measured in the pattern coordinate system.
54
- patternDict.putNumber('XStep', 1000);
55
- await patternDict.putNumber('YStep', 1000);
56
-
57
- return patternDict; // finished creating the Pattern resource
58
- }
59
-
60
- const createImageTilingPattern = async (doc) => {
61
- const writer = await PDFNet.ElementWriter.create();
62
- const eb = await PDFNet.ElementBuilder.create();
63
-
64
- // Create a new pattern content stream - a single bitmap object ----------
65
- writer.begin(doc);
66
- const image = await PDFNet.Image.createFromFile(doc, '../TestFiles/dice.jpg');
67
- const imgElement = await eb.createImageScaled(image, 0, 0, await image.getImageWidth(), await image.getImageHeight());
68
- writer.writePlacedElement(imgElement);
69
-
70
- const patternDict = await writer.end();
71
-
72
- // Initialize pattern dictionary. For details on what each parameter represents please
73
- // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
74
- patternDict.putName('Type', 'Pattern');
75
- patternDict.putNumber('PatternType', 1);
76
-
77
- // TilingType - Constant spacing.
78
- patternDict.putNumber('TilingType', 1);
79
-
80
- // This is a Type1 pattern - A colored tiling pattern.
81
- patternDict.putNumber('PaintType', 1);
82
-
83
- // Set bounding box
84
- patternDict.putRect('BBox', -253, 0, 253, 545);
85
-
86
- // Create and set the matrix
87
- const pattern_mtx = await PDFNet.Matrix2D.create(0.3, 0, 0, 0.3, 0, 0);
88
- patternDict.putMatrix('Matrix', pattern_mtx);
89
-
90
- // Set the desired horizontal and vertical spacing between pattern cells,
91
- // measured in the pattern coordinate system.
92
- patternDict.putNumber('XStep', 300);
93
- await patternDict.putNumber('YStep', 300);
94
-
95
- return patternDict; // finished creating the Pattern resource
96
- }
97
-
98
- const createAxialShading = async (doc) => {
99
- // Create a new Shading object ------------
100
- const patternDict = await doc.createIndirectDict();
101
-
102
- // Initialize pattern dictionary. For details on what each parameter represents
103
- // please refer to Tables 4.30 and 4.26 in PDF Reference Manual
104
- patternDict.putName('Type', 'Pattern');
105
- patternDict.putNumber('PatternType', 2); // 2 stands for shading
106
-
107
- const shadingDict = await patternDict.putDict('Shading');
108
- shadingDict.putNumber('ShadingType', 2);
109
- shadingDict.putName('ColorSpace', 'DeviceCMYK');
110
-
111
- // pass the coordinates of the axial shading to the output
112
- const shadingCoords = await shadingDict.putArray('Coords');
113
- shadingCoords.pushBackNumber(0);
114
- shadingCoords.pushBackNumber(0);
115
- shadingCoords.pushBackNumber(612);
116
- shadingCoords.pushBackNumber(794);
117
-
118
- // pass the function to the axial shading
119
- const func = await shadingDict.putDict('Function');
120
- const C0 = await func.putArray('C0');
121
- C0.pushBackNumber(1);
122
- C0.pushBackNumber(0);
123
- C0.pushBackNumber(0);
124
- await C0.pushBackNumber(0);
125
-
126
- const C1 = await func.putArray('C1');
127
- C1.pushBackNumber(0);
128
- C1.pushBackNumber(1);
129
- C1.pushBackNumber(0);
130
- await C1.pushBackNumber(0);
131
-
132
- const domain = await func.putArray('Domain');
133
- domain.pushBackNumber(0);
134
- await domain.pushBackNumber(1);
135
-
136
- func.putNumber('FunctionType', 2);
137
- await func.putNumber('N', 1);
138
-
139
- return patternDict;
140
- }
141
-
142
- const main = async () => {
143
- try {
144
- const doc = await PDFNet.PDFDoc.create();
145
- const writer = await PDFNet.ElementWriter.create();
146
- var eb = await PDFNet.ElementBuilder.create();
147
-
148
- // The following sample illustrates how to create and use tiling patterns
149
- var page = await doc.pageCreate();
150
- writer.beginOnPage(page);
151
-
152
- var element = await eb.createTextBeginWithFont(await PDFNet.Font.createAndEmbed(doc, PDFNet.Font.StandardType1Font.e_times_bold), 1);
153
- writer.writeElement(element); // Begin the text block
154
-
155
- const data = 'G';
156
- element = await eb.createNewTextRun(data);
157
- element.setTextMatrixEntries(720, 0, 0, 720, 20, 240);
158
- var gs = await element.getGState();
159
- gs.setTextRenderMode(PDFNet.GState.TextRenderingMode.e_fill_stroke_text);
160
- gs.setLineWidth(4);
161
-
162
- // Set the fill color space to the Pattern color space.
163
- gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
164
- var patterColor = await PDFNet.PatternColor.create(await createTilingPattern(doc));
165
- gs.setFillColorWithPattern(patterColor);
166
-
167
- writer.writeElement(element);
168
- writer.writeElement(await eb.createTextEnd()); // Finish the text block
169
-
170
- writer.end(); // Save the page
171
- doc.pagePushBack(page);
172
- //-----------------------------------------------
173
-
174
- /// The following sample illustrates how to create and use image tiling pattern
175
- page = await doc.pageCreate();
176
- writer.beginOnPage(page);
177
-
178
- eb.reset();
179
- element = await eb.createRect(0, 0, 612, 794);
180
-
181
- // Set the fill color space to the Pattern color space.
182
- gs = await element.getGState();
183
- gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
184
- patterColor = await PDFNet.PatternColor.create(await createImageTilingPattern(doc));
185
- gs.setFillColorWithPattern(patterColor);
186
- element.setPathFill(true);
187
-
188
- writer.writeElement(element);
189
-
190
- await writer.end(); // Save the page
191
- doc.pagePushBack(page);
192
- //-----------------------------------------------
193
-
194
- /// The following sample illustrates how to create and use PDF shadings
195
- page = await doc.pageCreate();
196
- writer.beginOnPage(page);
197
-
198
- eb.reset();
199
- element = await eb.createRect(0, 0, 612, 794);
200
-
201
- // Set the fill color space to the Pattern color space.
202
- gs = await element.getGState();
203
- gs.setFillColorSpace(await PDFNet.ColorSpace.createPattern());
204
- patterColor = await PDFNet.PatternColor.create(await createAxialShading(doc));
205
- gs.setFillColorWithPattern(patterColor);
206
- element.setPathFill(true);
207
-
208
- writer.writeElement(element);
209
-
210
- await writer.end(); // Save the page
211
- doc.pagePushBack(page);
212
- //-----------------------------------------------
213
-
214
- await doc.save('../TestFiles/Output/patterns.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
215
- console.log('Done. Result saved in patterns.pdf...');
216
- } catch (err) {
217
- console.log(err);
218
- }
219
- }
220
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
221
- console.log('Error: ' + JSON.stringify(error));
222
- }).then(function(){ return PDFNet.shutdown(); });
223
- };
224
- exports.runPatternTest();
225
- })(exports);
226
- // eslint-disable-next-line spaced-comment
227
- //# sourceURL=PatternTest.js
@@ -1,41 +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
- const { PDFNet } = require('@pdftron/pdfnet-node');
8
- const PDFTronLicense = require('../LicenseKey/LicenseKey');
9
-
10
- ((exports) => {
11
-
12
- exports.runRectTest = () => {
13
-
14
- const main = async() => {
15
- try {
16
- console.log('_______________________________________________');
17
- console.log('Opening the input pdf...');
18
-
19
- const inputPath = '../TestFiles/';
20
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'tiger.pdf');
21
- doc.initSecurityHandler();
22
-
23
- const pgItr1 = await doc.getPageIterator();
24
- const mediaBox = await (await pgItr1.current()).getMediaBox();
25
- mediaBox.x1 -= 200; // translate page 200 units left(1 uint = 1/72 inch)
26
- mediaBox.x2 -= 200;
27
-
28
- await mediaBox.update();
29
-
30
- await doc.save(inputPath + 'Output/tiger_shift.pdf', 0);
31
- console.log('Done. Result saved in tiger_shift...');
32
- } catch (err) {
33
- console.log(err);
34
- }
35
- };
36
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
37
- };
38
- exports.runRectTest();
39
- })(exports);
40
- // eslint-disable-next-line spaced-comment
41
- //# sourceURL=AnnotationTest.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
- // This sample illustrates how to use basic SDF API (also known as Cos) to edit an
7
- // existing document.
8
-
9
- const { PDFNet } = require('@pdftron/pdfnet-node');
10
- const PDFTronLicense = require('../LicenseKey/LicenseKey');
11
-
12
- ((exports) => {
13
-
14
- exports.runSDFTest = () => {
15
-
16
- const main = async() => {
17
- // Relative path to the folder containing test files.
18
- const inputPath = '../TestFiles/';
19
-
20
- try {
21
- console.log('Opening the test file...');
22
- // Here we create a SDF/Cos document directly from PDF file. In case you have
23
- // PDFDoc you can always access SDF/Cos document using PDFDoc.GetSDFDoc() method.
24
- const docorig = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'fish.pdf');
25
- const doc = await docorig.getSDFDoc();
26
- doc.initSecurityHandler();
27
- console.log('Modifying into dictionary, adding custom properties, embedding a stream...');
28
-
29
- const trailer = await doc.getTrailer(); // Get the trailer
30
-
31
- // Now we will change PDF document information properties using SDF API
32
-
33
- // Get the Info dictionary.
34
-
35
- let itr = await trailer.find('Info');
36
- let info;
37
- if (await itr.hasNext()) {
38
- info = await itr.value();
39
- // Modify 'Producer' entry.
40
- info.putString('Producer', 'PDFTron PDFNet');
41
-
42
- // read title entry if it is present
43
- itr = await info.find('Author');
44
- if (await itr.hasNext()) {
45
- const itrval = await itr.value();
46
- const oldstr = await itrval.getAsPDFText();
47
- info.putText('Author', oldstr + ' - Modified');
48
- } else {
49
- info.putString('Author', 'Me, myself, and I');
50
- }
51
- } else {
52
- // Info dict is missing.
53
- info = await trailer.putDict('Info');
54
- info.putString('Producer', 'PDFTron PDFNet');
55
- info.putString('Title', 'My document');
56
- }
57
-
58
- // Create a custom inline dictionary within Infor dictionary
59
- const customDict = await info.putDict('My Direct Dict');
60
- customDict.putNumber('My Number', 100); // Add some key/value pairs
61
- customDict.putArray('My Array');
62
-
63
- // Create a custom indirect array within Info dictionary
64
- const customArray = await doc.createIndirectArray();
65
- info.put('My Indirect Array', customArray); // Add some entries
66
-
67
- // create indirect link to root
68
- const trailerRoot = await trailer.get('Root');
69
- customArray.pushBack((await trailerRoot.value()));
70
-
71
- // Embed a custom stream (file mystream.txt).
72
- const embedFile = await PDFNet.Filter.createMappedFileFromUString(inputPath + 'my_stream.txt');
73
- const mystm = await PDFNet.FilterReader.create(embedFile);
74
- const indStream = await doc.createIndirectStreamFromFilter(mystm);
75
- customArray.pushBack(indStream);
76
-
77
- console.log('Saving modified test file...');
78
- await doc.save(inputPath + 'Output/sdftest_out.pdf', 0, '%PDF-1.4');
79
- console.log('Test completed.');
80
- } catch (err) {
81
- console.log(err);
82
- }
83
- };
84
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error){console.log('Error: ' + JSON.stringify(error));}).then(function(){return PDFNet.shutdown();});
85
- };
86
- exports.runSDFTest();
87
- })(exports);
88
- // eslint-disable-next-line spaced-comment
89
- //# sourceURL=SDFTest.js
@@ -1,256 +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 following sample shows how to add new content (or watermark) PDF pages
8
- // using 'pdftron.PDF.Stamper' utility class.
9
- //
10
- // Stamper can be used to PDF pages with text, images, or with other PDF content
11
- // in only a few lines of code. Although Stamper is very simple to use compared
12
- // to ElementBuilder/ElementWriter it is not as powerful or flexible. In case you
13
- // need full control over PDF creation use ElementBuilder/ElementWriter to add
14
- // new content to existing PDF pages as shown in the ElementBuilder sample project.
15
- //---------------------------------------------------------------------------------------
16
-
17
- const { PDFNet } = require('@pdftron/pdfnet-node');
18
- const PDFTronLicense = require('../LicenseKey/LicenseKey');
19
-
20
- ((exports) => {
21
-
22
- exports.runStamperTest = () => {
23
-
24
- const main = async () => {
25
- // Relative path to the folder containing test files.
26
- const inputPath = '../TestFiles/';
27
- const outputPath = inputPath + 'Output/';
28
-
29
- //--------------------------------------------------------------------------------
30
- // Example 1) Add text stamp to all pages, then remove text stamp from odd pages.
31
- try {
32
- // start stack-based deallocation with startDeallocateStack. Later on when endDeallocateStack is called,
33
- // all objects in memory that were initialized since the most recent startDeallocateStack call will be
34
- // cleaned up. Doing this makes sure that memory growth does not get too high.
35
- await PDFNet.startDeallocateStack();
36
-
37
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
38
- doc.initSecurityHandler();
39
-
40
- const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.5, 0.5); // Stamp size is relative to the size of the crop box of the destination page
41
- stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_center, PDFNet.Stamper.VerticalAlignment.e_vertical_center);
42
-
43
- const redColorPt = await PDFNet.ColorPt.init(1, 0, 0);
44
- stamper.setFontColor(redColorPt);
45
- const pgSet = await PDFNet.PageSet.createRange(1, (await doc.getPageCount()));
46
- stamper.stampText(doc, 'If you are reading this\nthis is an even page', pgSet);
47
- const oddPgSet = await PDFNet.PageSet.createFilteredRange(1, (await doc.getPageCount()), PDFNet.PageSet.Filter.e_odd);
48
- // delete all text stamps in odd pages
49
- PDFNet.Stamper.deleteStamps(doc, oddPgSet);
50
-
51
- await doc.save(outputPath + 'newsletter.ex1.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
52
-
53
- await PDFNet.endDeallocateStack();
54
- } catch (err) {
55
- console.log(err.stack);
56
- }
57
-
58
- //--------------------------------------------------------------------------------
59
- // Example 2) Add Image stamp to first 2 pages.
60
- try {
61
- await PDFNet.startDeallocateStack();
62
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
63
- doc.initSecurityHandler();
64
-
65
- const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.5, 0.5);
66
- const img = await PDFNet.Image.createFromFile(doc, inputPath + 'peppers.jpg');
67
- stamper.setSize(PDFNet.Stamper.SizeType.e_relative_scale, 0.5, 0.5);
68
- // set position of the image to the center, left of PDF pages
69
- stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_left, PDFNet.Stamper.VerticalAlignment.e_vertical_center);
70
-
71
- const blackColorPt = await PDFNet.ColorPt.init(0, 0, 0, 0);
72
- stamper.setFontColor(blackColorPt);
73
- stamper.setRotation(180);
74
- stamper.setAsBackground(false);
75
- // only stamp first 2 pages
76
- const pgSet = await PDFNet.PageSet.createRange(1, 2);
77
- stamper.stampImage(doc, img, pgSet);
78
-
79
- await doc.save(outputPath + 'newsletter.ex2.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
80
- await PDFNet.endDeallocateStack();
81
- } catch (err) {
82
- console.log(err.stack);
83
- }
84
-
85
- //--------------------------------------------------------------------------------
86
- // Example 3) Add Page stamp to all pages.
87
- try {
88
- await PDFNet.startDeallocateStack();
89
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
90
- doc.initSecurityHandler();
91
- const fishDoc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'fish.pdf');
92
- fishDoc.initSecurityHandler();
93
-
94
- const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.5, 0.5);
95
- const srcPage = await fishDoc.getPage(1);
96
- const pageOneCrop = await srcPage.getCropBox();
97
- // set size of the image to 10% of the original while keep the old aspect ratio
98
- stamper.setSize(PDFNet.Stamper.SizeType.e_absolute_size, (await pageOneCrop.width()) * 0.1, -1);
99
- stamper.setOpacity(0.4);
100
- stamper.setRotation(-67);
101
-
102
- // put the image at the bottom right hand corner
103
- stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_right, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
104
- const pgSet = await PDFNet.PageSet.createRange(1, (await doc.getPageCount()));
105
- stamper.stampPage(doc, srcPage, pgSet);
106
-
107
- await doc.save(outputPath + 'newsletter.ex3.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
108
- await PDFNet.endDeallocateStack();
109
- } catch (err) {
110
- console.log(err.stack);
111
- }
112
-
113
- //--------------------------------------------------------------------------------
114
- // Example 4) Add Image stamp to first 20 odd pages.
115
- try {
116
- await PDFNet.startDeallocateStack();
117
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
118
- doc.initSecurityHandler();
119
-
120
- const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_absolute_size, 20, 20);
121
- stamper.setOpacity(1);
122
- stamper.setRotation(45);
123
- stamper.setAsBackground(true);
124
- stamper.setPosition(30, 40);
125
- const img = await PDFNet.Image.createFromFile(doc, inputPath + 'peppers.jpg');
126
-
127
- const pgSet = await PDFNet.PageSet.createFilteredRange(1, 20, PDFNet.PageSet.Filter.e_odd);
128
- stamper.stampImage(doc, img, pgSet);
129
-
130
- await doc.save(outputPath + 'newsletter.ex4.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
131
- await PDFNet.endDeallocateStack();
132
- } catch (err) {
133
- console.log(err.stack);
134
- }
135
-
136
- //--------------------------------------------------------------------------------
137
- // Example 5) Add text stamp to first 20 even pages
138
- try {
139
- await PDFNet.startDeallocateStack();
140
-
141
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
142
- doc.initSecurityHandler();
143
-
144
- const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.05, 0.05);
145
- stamper.setPosition(0, 0);
146
- stamper.setOpacity(0.7);
147
- stamper.setRotation(90);
148
- stamper.setSize(PDFNet.Stamper.SizeType.e_font_size, 80, -1);
149
- stamper.setTextAlignment(PDFNet.Stamper.TextAlignment.e_align_center);
150
- const pgSet = await PDFNet.PageSet.createFilteredRange(1, 20, PDFNet.PageSet.Filter.e_even);
151
- stamper.stampText(doc, 'Goodbye\nMoon', pgSet);
152
-
153
- await doc.save(outputPath + 'newsletter.ex5.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
154
-
155
- await PDFNet.endDeallocateStack();
156
- } catch (err) {
157
- console.log(err.stack);
158
- }
159
-
160
- //--------------------------------------------------------------------------------
161
- // Example 6) Add first page as stamp to all even pages
162
- try {
163
- await PDFNet.startDeallocateStack();
164
-
165
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
166
- doc.initSecurityHandler();
167
-
168
- const fishDoc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'fish.pdf');
169
- fishDoc.initSecurityHandler();
170
-
171
- const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.3, 0.3);
172
- stamper.setOpacity(1);
173
- stamper.setRotation(270);
174
- stamper.setAsBackground(true);
175
- stamper.setPosition(0.5, 0.5, true);
176
- stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_left, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
177
- const pgOne = await fishDoc.getPage(1);
178
- const pgSet = await PDFNet.PageSet.createFilteredRange(1, await doc.getPageCount(), PDFNet.PageSet.Filter.e_even);
179
- stamper.stampPage(doc, pgOne, pgSet);
180
-
181
- await doc.save(outputPath + 'newsletter.ex6.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
182
-
183
- await PDFNet.endDeallocateStack();
184
- } catch (err) {
185
- console.log(err.stack);
186
- }
187
-
188
- //--------------------------------------------------------------------------------
189
- // Example 7) Add image stamp at top right corner in every pages
190
- try {
191
- await PDFNet.startDeallocateStack();
192
-
193
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
194
- doc.initSecurityHandler();
195
-
196
- const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.1, 0.1);
197
- stamper.setOpacity(0.8);
198
- stamper.setRotation(135);
199
- stamper.setAsBackground(false);
200
- stamper.showsOnPrint(false);
201
- stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_left, PDFNet.Stamper.VerticalAlignment.e_vertical_top);
202
- stamper.setPosition(10, 10);
203
-
204
- const img = await PDFNet.Image.createFromFile(doc, inputPath + 'peppers.jpg');
205
- const pgSet = await PDFNet.PageSet.createFilteredRange(1, (await doc.getPageCount()), PDFNet.PageSet.Filter.e_all);
206
- stamper.stampImage(doc, img, pgSet);
207
-
208
- await doc.save(outputPath + 'newsletter.ex7.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
209
-
210
- await PDFNet.endDeallocateStack();
211
- } catch (err) {
212
- console.log(err.stack);
213
- }
214
-
215
- //--------------------------------------------------------------------------------
216
- // Example 8) Add Text stamp to first 2 pages, and image stamp to first page.
217
- // Because text stamp is set as background, the image is top of the text
218
- // stamp. Text stamp on the first page is not visible.
219
- try {
220
- await PDFNet.startDeallocateStack();
221
-
222
- const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
223
- doc.initSecurityHandler();
224
-
225
- const stamper = await PDFNet.Stamper.create(PDFNet.Stamper.SizeType.e_relative_scale, 0.07, -0.1);
226
- stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_right, PDFNet.Stamper.VerticalAlignment.e_vertical_bottom);
227
- stamper.setAlignment(PDFNet.Stamper.HorizontalAlignment.e_horizontal_center, PDFNet.Stamper.VerticalAlignment.e_vertical_top);
228
- const font = await PDFNet.Font.create(doc, PDFNet.Font.StandardType1Font.e_courier);
229
- stamper.setFont(font);
230
- const redColorPt = await PDFNet.ColorPt.init(1, 0, 0, 0);
231
- stamper.setFontColor(redColorPt);
232
- stamper.setTextAlignment(PDFNet.Stamper.TextAlignment.e_align_right);
233
- stamper.setAsBackground(true);
234
-
235
- const pgSet = await PDFNet.PageSet.createRange(1, 2);
236
- stamper.stampText(doc, 'This is a title!', pgSet);
237
-
238
- const img = await PDFNet.Image.createFromFile(doc, inputPath + 'peppers.jpg');
239
- stamper.setAsBackground(false);
240
-
241
- const pgSetImage = await PDFNet.PageSet.createRange(1, 1);
242
- stamper.stampImage(doc, img, pgSetImage);
243
-
244
- await doc.save(outputPath + 'newsletter.ex8.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
245
-
246
- await PDFNet.endDeallocateStack();
247
- } catch (err) {
248
- console.log(err.stack);
249
- }
250
- };
251
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
252
- };
253
- exports.runStamperTest();
254
- })(exports);
255
- // eslint-disable-next-line spaced-comment
256
- //# sourceURL=StamperTest.js
Binary file