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

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 (147) hide show
  1. package/package.json +18 -18
  2. package/readme.md +12 -12
  3. package/samples/AddImageTest/AddImageTest.js +1 -1
  4. package/samples/AddImageTest/NODEJS/AddImageTest.js +116 -0
  5. package/samples/AddImageTest/NODEJS/RunTest.sh +2 -0
  6. package/samples/AdvancedImagingTest/AdvancedImagingTest.js +1 -1
  7. package/samples/AdvancedImagingTest/NODEJS/AdvancedImagingTest.js +78 -0
  8. package/samples/AdvancedImagingTest/NODEJS/RunTest.sh +2 -0
  9. package/samples/AnnotationTest/AnnotationTest.js +1 -1
  10. package/samples/AnnotationTest/NODEJS/AnnotationTest.js +642 -0
  11. package/samples/AnnotationTest/NODEJS/RunTest.sh +2 -0
  12. package/samples/BookmarkTest/BookmarkTest.js +1 -1
  13. package/samples/BookmarkTest/NODEJS/BookmarkTest.js +220 -0
  14. package/samples/BookmarkTest/NODEJS/RunTest.sh +2 -0
  15. package/samples/CAD2PDFTest/CAD2PDFTest.js +79 -79
  16. package/samples/CAD2PDFTest/NODEJS/CAD2PDFTest.js +80 -0
  17. package/samples/CAD2PDFTest/NODEJS/RunTest.sh +2 -0
  18. package/samples/ContentReplacerTest/ContentReplacerTest.js +1 -1
  19. package/samples/ContentReplacerTest/NODEJS/ContentReplacerTest.js +75 -0
  20. package/samples/ContentReplacerTest/NODEJS/RunTest.sh +2 -0
  21. package/samples/ConvertTest/ConvertTest.js +270 -256
  22. package/samples/ConvertTest/NODEJS/ConvertTest.js +270 -0
  23. package/samples/ConvertTest/NODEJS/RunTest.sh +2 -0
  24. package/samples/DataExtractionTest/DataExtractionTest.js +180 -0
  25. package/samples/DataExtractionTest/NODEJS/DataExtractionTest.js +180 -0
  26. package/samples/DataExtractionTest/NODEJS/RunTest.sh +2 -0
  27. package/samples/DigitalSignaturesTest/DigitalSignaturesTest.js +526 -526
  28. package/samples/DigitalSignaturesTest/NODEJS/DigitalSignaturesTest.js +527 -0
  29. package/samples/DigitalSignaturesTest/NODEJS/RunTest.sh +2 -0
  30. package/samples/ElementBuilderTest/ElementBuilderTest.js +1 -1
  31. package/samples/ElementBuilderTest/NODEJS/ElementBuilderTest.js +514 -0
  32. package/samples/ElementBuilderTest/NODEJS/RunTest.sh +2 -0
  33. package/samples/ElementEditTest/ElementEditTest.js +1 -1
  34. package/samples/ElementEditTest/NODEJS/ElementEditTest.js +111 -0
  35. package/samples/ElementEditTest/NODEJS/RunTest.sh +2 -0
  36. package/samples/ElementReaderAdvTest/ElementReaderAdvTest.js +1 -1
  37. package/samples/ElementReaderAdvTest/NODEJS/ElementReaderAdvTest.js +305 -0
  38. package/samples/ElementReaderAdvTest/NODEJS/RunTest.sh +2 -0
  39. package/samples/ElementReaderTest/ElementReaderTest.js +1 -1
  40. package/samples/ElementReaderTest/NODEJS/ElementReaderTest.js +77 -0
  41. package/samples/ElementReaderTest/NODEJS/RunTest.sh +2 -0
  42. package/samples/EncTest/EncTest.js +1 -1
  43. package/samples/EncTest/NODEJS/EncTest.js +176 -0
  44. package/samples/EncTest/NODEJS/RunTest.sh +2 -0
  45. package/samples/FDFTest/FDFTest.js +218 -218
  46. package/samples/FDFTest/NODEJS/FDFTest.js +219 -0
  47. package/samples/FDFTest/NODEJS/RunTest.sh +2 -0
  48. package/samples/HTML2PDFTest/HTML2PDFTest.js +165 -165
  49. package/samples/HTML2PDFTest/NODEJS/HTML2PDFTest.js +166 -0
  50. package/samples/HTML2PDFTest/NODEJS/RunTest.sh +2 -0
  51. package/samples/HighlightsTest/HighlightsTest.js +1 -1
  52. package/samples/HighlightsTest/NODEJS/HighlightsTest.js +97 -0
  53. package/samples/HighlightsTest/NODEJS/RunTest.sh +2 -0
  54. package/samples/ImageExtractTest/ImageExtractTest.js +129 -129
  55. package/samples/ImageExtractTest/NODEJS/ImageExtractTest.js +130 -0
  56. package/samples/ImageExtractTest/NODEJS/RunTest.sh +2 -0
  57. package/samples/ImpositionTest/ImpositionTest.js +86 -86
  58. package/samples/ImpositionTest/NODEJS/ImpositionTest.js +87 -0
  59. package/samples/ImpositionTest/NODEJS/RunTest.sh +2 -0
  60. package/samples/InteractiveFormsTest/InteractiveFormsTest.js +381 -381
  61. package/samples/InteractiveFormsTest/NODEJS/InteractiveFormsTest.js +382 -0
  62. package/samples/InteractiveFormsTest/NODEJS/RunTest.sh +2 -0
  63. package/samples/JBIG2Test/JBIG2Test.js +88 -88
  64. package/samples/JBIG2Test/NODEJS/JBIG2Test.js +89 -0
  65. package/samples/JBIG2Test/NODEJS/RunTest.sh +2 -0
  66. package/samples/LicenseKey/NODEJS/LicenseKey.js +11 -0
  67. package/samples/LogicalStructureTest/LogicalStructureTest.js +1 -1
  68. package/samples/LogicalStructureTest/NODEJS/LogicalStructureTest.js +251 -0
  69. package/samples/LogicalStructureTest/NODEJS/RunTest.sh +2 -0
  70. package/samples/OCRTest/NODEJS/OCRTest.js +235 -0
  71. package/samples/OCRTest/NODEJS/RunTest.sh +2 -0
  72. package/samples/OCRTest/OCRTest.js +234 -234
  73. package/samples/OfficeTemplateTest/NODEJS/OfficeTemplateTest.js +79 -0
  74. package/samples/OfficeTemplateTest/NODEJS/RunTest.sh +2 -0
  75. package/samples/OfficeTemplateTest/OfficeTemplateTest.js +79 -77
  76. package/samples/OfficeToPDFTest/NODEJS/OfficeToPDFTest.js +125 -0
  77. package/samples/OfficeToPDFTest/NODEJS/RunTest.sh +2 -0
  78. package/samples/OfficeToPDFTest/OfficeToPDFTest.js +125 -125
  79. package/samples/OptimizerTest/NODEJS/OptimizerTest.js +192 -0
  80. package/samples/OptimizerTest/NODEJS/RunTest.sh +2 -0
  81. package/samples/OptimizerTest/OptimizerTest.js +191 -191
  82. package/samples/PDF2HtmlTest/NODEJS/PDF2HtmlTest.js +123 -0
  83. package/samples/PDF2HtmlTest/NODEJS/RunTest.sh +2 -0
  84. package/samples/PDF2HtmlTest/PDF2HtmlTest.js +1 -1
  85. package/samples/PDF2OfficeTest/NODEJS/PDF2OfficeTest.js +158 -0
  86. package/samples/PDF2OfficeTest/NODEJS/RunTest.sh +2 -0
  87. package/samples/PDF2OfficeTest/PDF2OfficeTest.js +1 -1
  88. package/samples/PDFATest/NODEJS/PDFATest.js +85 -0
  89. package/samples/PDFATest/NODEJS/RunTest.sh +2 -0
  90. package/samples/PDFATest/PDFATest.js +1 -1
  91. package/samples/PDFDocMemoryTest/NODEJS/PDFDocMemoryTest.js +85 -0
  92. package/samples/PDFDocMemoryTest/NODEJS/RunTest.sh +2 -0
  93. package/samples/PDFDocMemoryTest/PDFDocMemoryTest.js +84 -84
  94. package/samples/PDFDrawTest/NODEJS/PDFDrawTest.js +306 -0
  95. package/samples/PDFDrawTest/NODEJS/RunTest.sh +2 -0
  96. package/samples/PDFDrawTest/PDFDrawTest.js +1 -1
  97. package/samples/PDFLayersTest/NODEJS/PDFLayersTest.js +295 -0
  98. package/samples/PDFLayersTest/NODEJS/RunTest.sh +2 -0
  99. package/samples/PDFLayersTest/PDFLayersTest.js +1 -1
  100. package/samples/PDFPackageTest/NODEJS/PDFPackageTest.js +112 -0
  101. package/samples/PDFPackageTest/NODEJS/RunTest.sh +2 -0
  102. package/samples/PDFPackageTest/PDFPackageTest.js +111 -111
  103. package/samples/PDFPageTest/NODEJS/PDFPageTest.js +190 -0
  104. package/samples/PDFPageTest/NODEJS/RunTest.sh +2 -0
  105. package/samples/PDFPageTest/PDFPageTest.js +1 -1
  106. package/samples/PDFRedactTest/NODEJS/PDFRedactTest.js +75 -0
  107. package/samples/PDFRedactTest/NODEJS/RunTest.sh +2 -0
  108. package/samples/PDFRedactTest/PDFRedactTest.js +1 -1
  109. package/samples/PageLabelsTest/NODEJS/PageLabelsTest.js +139 -0
  110. package/samples/PageLabelsTest/NODEJS/RunTest.sh +2 -0
  111. package/samples/PageLabelsTest/PageLabelsTest.js +138 -138
  112. package/samples/PatternTest/NODEJS/PatternTest.js +227 -0
  113. package/samples/PatternTest/NODEJS/RunTest.sh +2 -0
  114. package/samples/PatternTest/PatternTest.js +226 -226
  115. package/samples/RectTest/NODEJS/RectTest.js +41 -0
  116. package/samples/RectTest/NODEJS/RunTest.sh +2 -0
  117. package/samples/RectTest/RectTest.js +1 -1
  118. package/samples/SDFTest/NODEJS/RunTest.sh +2 -0
  119. package/samples/SDFTest/NODEJS/SDFTest.js +88 -0
  120. package/samples/SDFTest/SDFTest.js +2 -3
  121. package/samples/StamperTest/NODEJS/RunTest.sh +2 -0
  122. package/samples/StamperTest/NODEJS/StamperTest.js +256 -0
  123. package/samples/StamperTest/StamperTest.js +1 -1
  124. package/samples/TestFiles/financial.pdf +0 -0
  125. package/samples/TestFiles/formfields-scanned.pdf +0 -0
  126. package/samples/TestFiles/formfields.pdf +0 -0
  127. package/samples/TestFiles/table.pdf +0 -0
  128. package/samples/TestFiles/tiger.svg +378 -0
  129. package/samples/TextExtractTest/NODEJS/RunTest.sh +2 -0
  130. package/samples/TextExtractTest/NODEJS/TextExtractTest.js +287 -0
  131. package/samples/TextExtractTest/TextExtractTest.js +1 -1
  132. package/samples/TextSearchTest/NODEJS/RunTest.sh +2 -0
  133. package/samples/TextSearchTest/NODEJS/TextSearchTest.js +122 -0
  134. package/samples/TextSearchTest/TextSearchTest.js +1 -1
  135. package/samples/U3DTest/NODEJS/RunTest.sh +2 -0
  136. package/samples/U3DTest/NODEJS/U3DTest.js +105 -0
  137. package/samples/U3DTest/U3DTest.js +104 -104
  138. package/samples/UndoRedoTest/NODEJS/RunTest.sh +2 -0
  139. package/samples/UndoRedoTest/NODEJS/UndoRedoTest.js +101 -0
  140. package/samples/UndoRedoTest/UndoRedoTest.js +1 -1
  141. package/samples/UnicodeWriteTest/NODEJS/RunTest.sh +2 -0
  142. package/samples/UnicodeWriteTest/NODEJS/UnicodeWriteTest.js +174 -0
  143. package/samples/UnicodeWriteTest/UnicodeWriteTest.js +1 -1
  144. package/samples/WebViewerConvertTest/NODEJS/RunTest.sh +2 -0
  145. package/samples/WebViewerConvertTest/NODEJS/WebViewerConvertTest.js +136 -0
  146. package/samples/WebViewerConvertTest/WebViewerConvertTest.js +135 -135
  147. package/samples/runall.bat +12 -12
@@ -0,0 +1,270 @@
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
+ //---------------------------------------------------------------------------------------
7
+ // The following sample illustrates how to use the PDF::Convert utility class to convert
8
+ // documents and files to PDF, XPS, SVG, or EMF.
9
+ //
10
+ // Certain file formats such as XPS, EMF, PDF, and raster image formats can be directly
11
+ // converted to PDF or XPS. Other formats are converted using a virtual driver. To check
12
+ // if ToPDF (or ToXPS) require that PDFNet printer is installed use Convert::RequiresPrinter(filename).
13
+ // The installing application must be run as administrator. The manifest for this sample
14
+ // specifies appropriate the UAC elevation.
15
+ //
16
+ // Note: the PDFNet printer is a virtual XPS printer supported on Vista SP1 and Windows 7.
17
+ // For Windows XP SP2 or higher, or Vista SP0 you need to install the XPS Essentials Pack (or
18
+ // equivalent redistributables). You can download the XPS Essentials Pack from:
19
+ // http://www.microsoft.com/downloads/details.aspx?FamilyId=B8DCFFDD-E3A5-44CC-8021-7649FD37FFEE&displaylang=en
20
+ // Windows XP Sp2 will also need the Microsoft Core XML Services (MSXML) 6.0:
21
+ // http://www.microsoft.com/downloads/details.aspx?familyid=993C0BCF-3BCF-4009-BE21-27E85E1857B1&displaylang=en
22
+ //
23
+ // Note: Convert.FromEmf and Convert.ToEmf will only work on Windows and require GDI+.
24
+ //
25
+ // Please contact us if you have any questions.
26
+ //---------------------------------------------------------------------------------------
27
+
28
+ const { PDFNet } = require('../../../lib/pdfnet.js');
29
+ const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
30
+
31
+ ((exports) => {
32
+ 'use strict';
33
+
34
+ let Testfile = function (inputFile, outputFile, requiresWindowsPlatform) {
35
+ this.inputFile = inputFile;
36
+ this.outputFile = outputFile;
37
+ this.requiresWindowsPlatform = requiresWindowsPlatform;
38
+ }
39
+
40
+ const testfiles = [
41
+ new Testfile('simple-word_2007.docx', 'docx2pdf.pdf', false),
42
+ new Testfile('simple-powerpoint_2007.pptx', 'pptx2pdf.pdf', false),
43
+ new Testfile('simple-excel_2007.xlsx', 'xlsx2pdf.pdf', false),
44
+ new Testfile('simple-publisher.pub', 'pub2pdf.pdf', true),
45
+ new Testfile('simple-text.txt', 'txt2pdf.pdf', false),
46
+ new Testfile('simple-rtf.rtf', 'rtf2pdf.pdf', true),
47
+ new Testfile('butterfly.png', 'png2pdf.pdf', false),
48
+ new Testfile('simple-emf.emf', 'emf2pdf.pdf', true),
49
+ new Testfile('simple-xps.xps', 'xps2pdf.pdf', false),
50
+ new Testfile('simple-webpage.html', 'html2pdf.pdf', true),
51
+ ]
52
+
53
+ const inputPath = '../../TestFiles/';
54
+ const outputPath = '../../TestFiles/Output/';
55
+
56
+ exports.runConvertTest = () => {
57
+
58
+ const main = async () => {
59
+ try {
60
+ await convertToPdfFromFile();
61
+ console.log('ConvertFile succeeded');
62
+ } catch (err) {
63
+ console.log('ConvertFile failed');
64
+ console.log(err);
65
+ }
66
+
67
+ try {
68
+ await convertSpecificFormats();
69
+ console.log('ConvertSpecificFormats succeeded');
70
+ } catch (err) {
71
+ console.log('ConvertSpecificFormats failed');
72
+ console.log(err);
73
+ }
74
+
75
+ if (process.platform === 'win32' && await PDFNet.Convert.printerIsInstalled()) {
76
+ try {
77
+ console.log('Uninstalling printer (requires Windows platform and administrator)');
78
+ await PDFNet.Convert.printerUninstall();
79
+ console.log('Uninstalled printer ' + await PDFNet.Convert.printerGetPrinterName());
80
+ } catch (err) {
81
+ console.log('Unable to uninstall printer');
82
+ }
83
+ }
84
+
85
+ console.log('Done.');
86
+ };
87
+
88
+ const convertToPdfFromFile = async () => {
89
+ if (process.platform === 'win32') {
90
+ if (await PDFNet.Convert.printerIsInstalled('PDFTron PDFNet')) {
91
+ await PDFNet.Convert.printerSetPrinterName('PDFTron PDFNet');
92
+ } else if (!(await PDFNet.Convert.printerIsInstalled())) {
93
+ try {
94
+ // This will fail if not run as administrator. Harmless if PDFNet
95
+ // printer already installed
96
+ console.log('Installing printer (requires Windows platform and administrator)');
97
+ await PDFNet.Convert.printerInstall();
98
+ console.log('Installed printer ' + await PDFNet.Convert.printerGetPrinterName());
99
+ } catch (err) {
100
+ console.log('Unable to install printer');
101
+ }
102
+ }
103
+ }
104
+
105
+ for (const testfile of testfiles) {
106
+ if (process.platform !== 'win32' && testfile.requiresWindowsPlatform) continue;
107
+
108
+ try {
109
+ const pdfdoc = await PDFNet.PDFDoc.create();
110
+ await pdfdoc.initSecurityHandler();
111
+ const inputFile = inputPath + testfile.inputFile;
112
+ const outputFile = outputPath + testfile.outputFile;
113
+ if (await PDFNet.Convert.requiresPrinter(inputFile)) {
114
+ console.log('Using PDFNet printer to convert file ' + testfile.inputFile);
115
+ }
116
+ await PDFNet.Convert.toPdf(pdfdoc, inputFile);
117
+ await pdfdoc.save(outputFile, PDFNet.SDFDoc.SaveOptions.e_linearized);
118
+ console.log('Converted file: ' + testfile.inputFile + '\nto: ' + testfile.outputFile);
119
+ } catch (err) {
120
+ console.log('Unable to convert file ' + testfile.inputFile);
121
+ console.log(err);
122
+ }
123
+ }
124
+ };
125
+
126
+ const convertSpecificFormats = async () => {
127
+ try {
128
+ const pdfdoc = await PDFNet.PDFDoc.create();
129
+ await pdfdoc.initSecurityHandler();
130
+
131
+ console.log('Converting from XPS');
132
+ await PDFNet.Convert.fromXps(pdfdoc, inputPath + 'simple-xps.xps');
133
+ await pdfdoc.save(outputPath + 'xps2pdf v2.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
134
+ console.log('Saved xps2pdf v2.pdf');
135
+ } catch (err) {
136
+ console.log(err);
137
+ }
138
+
139
+ if (process.platform === 'win32') {
140
+ try {
141
+ const pdfdoc = await PDFNet.PDFDoc.create();
142
+ await pdfdoc.initSecurityHandler();
143
+
144
+ console.log('Converting from EMF');
145
+ await PDFNet.Convert.fromEmf(pdfdoc, inputPath + 'simple-emf.emf');
146
+ await pdfdoc.save(outputPath + 'emf2pdf v2.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
147
+ console.log('Saved emf2pdf v2.pdf');
148
+ } catch (err) {
149
+ console.log(err);
150
+ }
151
+ }
152
+
153
+ try {
154
+ const pdfdoc = await PDFNet.PDFDoc.create();
155
+ await pdfdoc.initSecurityHandler();
156
+
157
+ // Add a dictionary
158
+ const set = await PDFNet.ObjSet.create();
159
+ const options = await set.createDict();
160
+
161
+ // Put options
162
+ options.putNumber('FontSize', 15);
163
+ options.putBool('UseSourceCodeFormatting', true);
164
+ options.putNumber('PageWidth', 12);
165
+ await options.putNumber('PageHeight', 6);
166
+
167
+ // Convert from .txt file
168
+ console.log('Converting from txt');
169
+ await PDFNet.Convert.fromText(pdfdoc, inputPath + 'simple-text.txt', options);
170
+ await pdfdoc.save(outputPath + 'simple-text.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
171
+ console.log('Saved simple-text.pdf');
172
+ } catch (err) {
173
+ console.log(err);
174
+ }
175
+
176
+ try {
177
+ const pdfdoc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'newsletter.pdf');
178
+ await pdfdoc.initSecurityHandler();
179
+
180
+ // Convert PDF document to SVG
181
+ console.log('Converting pdfdoc to SVG');
182
+ await PDFNet.Convert.docToSvg(pdfdoc, outputPath + 'pdf2svg v2.svg');
183
+ console.log('Saved pdf2svg v2.svg');
184
+ } catch (err) {
185
+ console.log(err);
186
+ }
187
+
188
+ try {
189
+ // Convert PNG image to XPS
190
+ console.log('Converting PNG to XPS');
191
+ await PDFNet.Convert.fileToXps(inputPath + 'butterfly.png', outputPath + 'butterfly.xps');
192
+ console.log('Saved butterfly.xps');
193
+ } catch (err) {
194
+ console.log(err);
195
+ }
196
+
197
+ if (process.platform === 'win32') {
198
+ try {
199
+ // Convert MSWord document to XPS
200
+ console.log('Converting DOCX to XPS');
201
+ await PDFNet.Convert.fileToXps(inputPath + 'simple-word_2007.docx', outputPath + 'simple-word_2007.xps');
202
+ console.log('Saved simple-word_2007.xps');
203
+ } catch (err) {
204
+ console.log(err);
205
+ }
206
+ }
207
+
208
+ try {
209
+ // Convert PDF document to XPS
210
+ console.log('Converting PDF to XPS');
211
+ await PDFNet.Convert.fileToXps(inputPath + 'newsletter.pdf', outputPath + 'newsletter.xps');
212
+ console.log('Saved newsletter.xps');
213
+ } catch (err) {
214
+ console.log(err);
215
+ }
216
+
217
+ try {
218
+ // Convert PDF document to HTML
219
+ console.log('Converting PDF to HTML');
220
+ await PDFNet.Convert.fileToHtml(inputPath + 'newsletter.pdf', outputPath + 'newsletter');
221
+ console.log('Saved newsletter as HTML');
222
+ } catch (err) {
223
+ console.log(err);
224
+ }
225
+
226
+ try {
227
+ // Convert PDF document to EPUB
228
+ console.log('Converting PDF to EPUB');
229
+ await PDFNet.Convert.fileToEpub(inputPath + 'newsletter.pdf', outputPath + 'newsletter.epub');
230
+ console.log('Saved newsletter.epub');
231
+ } catch (err) {
232
+ console.log(err);
233
+ }
234
+
235
+ try {
236
+ // Convert PDF document to multipage TIFF
237
+ console.log('Converting PDF to multipage TIFF');
238
+ const tiff_options = new PDFNet.Convert.TiffOutputOptions();
239
+ tiff_options.setDPI(200);
240
+ tiff_options.setDither(true);
241
+ tiff_options.setMono(true);
242
+
243
+ await PDFNet.Convert.fileToTiff(inputPath + 'newsletter.pdf', outputPath + 'newsletter.tiff', tiff_options);
244
+ console.log('Saved newsletter.tiff');
245
+ } catch (err) {
246
+ console.log(err);
247
+ }
248
+
249
+ try {
250
+ const pdfdoc = await PDFNet.PDFDoc.create();
251
+ await pdfdoc.initSecurityHandler();
252
+
253
+ // Convert SVG file to PDF
254
+ console.log('Converting SVG to PDF');
255
+ await PDFNet.Convert.fromSVG(pdfdoc, inputPath + 'tiger.svg');
256
+ await pdfdoc.save(outputPath + 'svg2pdf.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
257
+
258
+ console.log('Saved svg2pdf.pdf');
259
+ } catch (err) {
260
+ console.log(err);
261
+ }
262
+ };
263
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
264
+ console.log('Error: ' + JSON.stringify(error));
265
+ }).then(function(){ return PDFNet.shutdown(); });
266
+ };
267
+ exports.runConvertTest();
268
+ })(exports);
269
+ // eslint-disable-next-line spaced-comment
270
+ //# sourceURL=ConvertTest.js
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node ConvertTest.js
@@ -0,0 +1,180 @@
1
+ //---------------------------------------------------------------------------------------
2
+ // Copyright (c) 2001-2023 by PDFTron Systems Inc. All Rights Reserved.
3
+ // Consult legal.txt regarding legal and license information.
4
+ //---------------------------------------------------------------------------------------
5
+
6
+ //---------------------------------------------------------------------------------------
7
+ // The Data Extraction suite is an optional PDFNet add-on collection that can be used to
8
+ // extract various types of data from PDF documents.
9
+ //
10
+ // The PDFTron SDK Data Extraction suite can be downloaded from http://www.pdftron.com/
11
+ //---------------------------------------------------------------------------------------
12
+
13
+ const fs = require('fs');
14
+ const { PDFNet } = require('@pdftron/pdfnet-node');
15
+ const PDFTronLicense = require('../LicenseKey/LicenseKey');
16
+
17
+ ((exports) => {
18
+ 'use strict';
19
+
20
+ exports.runDataExtractionTest = () => {
21
+
22
+ const main = async () => {
23
+
24
+ const inputPath = '../TestFiles/';
25
+ const outputPath = '../TestFiles/Output/';
26
+
27
+ //////////////////////////////////////////////////////////////////////////
28
+
29
+ await PDFNet.addResourceSearchPath('../../lib/');
30
+
31
+ //////////////////////////////////////////////////////////////////////////
32
+ // The following sample illustrates how to extract tables from PDF documents.
33
+ //////////////////////////////////////////////////////////////////////////
34
+
35
+ // Test if the add-on is installed
36
+ if (!await PDFNet.DataExtractionModule.isModuleAvailable(PDFNet.DataExtractionModule.DataExtractionEngine.e_Tabular)) {
37
+ console.log('\nUnable to run Data Extraction: PDFTron SDK Tabular Data module not available.');
38
+ console.log('---------------------------------------------------------------');
39
+ console.log('The Data Extraction suite is an optional add-on, available for download');
40
+ console.log('at https://www.pdftron.com/documentation/core/info/modules/. If you have already');
41
+ console.log('downloaded this module, ensure that the SDK is able to find the required files');
42
+ console.log('using the PDFNet.addResourceSearchPath() function.\n');
43
+ }
44
+ else
45
+ {
46
+ try {
47
+ // Extract tabular data as a JSON file
48
+ console.log('Extract tabular data as a JSON file');
49
+
50
+ let outputFile = outputPath + 'table.json';
51
+ await PDFNet.DataExtractionModule.extractData(inputPath + 'table.pdf', outputFile, PDFNet.DataExtractionModule.DataExtractionEngine.e_Tabular);
52
+
53
+ console.log('Result saved in ' + outputFile);
54
+
55
+ ///////////////////////////////////////////////////////
56
+ // Extract tabular data as a JSON string
57
+ console.log('Extract tabular data as a JSON string');
58
+
59
+ outputFile = outputPath + 'financial.json';
60
+ const json = await PDFNet.DataExtractionModule.extractDataAsString(inputPath + 'financial.pdf', PDFNet.DataExtractionModule.DataExtractionEngine.e_Tabular);
61
+ fs.writeFileSync(outputFile, json);
62
+
63
+ console.log('Result saved in ' + outputFile);
64
+
65
+ ///////////////////////////////////////////////////////
66
+ // Extract tabular data as an XLSX file
67
+ console.log('Extract tabular data as an XLSX file');
68
+
69
+ outputFile = outputPath + 'table.xlsx';
70
+ await PDFNet.DataExtractionModule.extractToXSLX(inputPath + 'table.pdf', outputFile);
71
+
72
+ console.log('Result saved in ' + outputFile);
73
+
74
+ ///////////////////////////////////////////////////////
75
+ // Extract tabular data as an XLSX stream (also known as filter)
76
+ console.log('Extract tabular data as an XLSX stream');
77
+
78
+ outputFile = outputPath + 'financial.xlsx';
79
+ const outputXlsxStream = await PDFNet.Filter.createMemoryFilter(0, false);
80
+ const options = new PDFNet.DataExtractionModule.DataExtractionOptions();
81
+ options.setPages("1"); // page 1
82
+ await PDFNet.DataExtractionModule.extractToXSLXWithFilter(inputPath + 'financial.pdf', outputXlsxStream, options);
83
+ outputXlsxStream.memoryFilterSetAsInputFilter();
84
+ outputXlsxStream.writeToFile(outputFile, false);
85
+
86
+ console.log('Result saved in ' + outputFile);
87
+ } catch (err) {
88
+ console.log(err);
89
+ }
90
+ }
91
+
92
+ //////////////////////////////////////////////////////////////////////////
93
+ // The following sample illustrates how to extract document structure from PDF documents.
94
+ //////////////////////////////////////////////////////////////////////////
95
+
96
+ // Test if the add-on is installed
97
+ if (!await PDFNet.DataExtractionModule.isModuleAvailable(PDFNet.DataExtractionModule.DataExtractionEngine.e_DocStructure)) {
98
+ console.log('\nUnable to run Data Extraction: PDFTron SDK Structured Output module not available.');
99
+ console.log('---------------------------------------------------------------');
100
+ console.log('The Data Extraction suite is an optional add-on, available for download');
101
+ console.log('at https://www.pdftron.com/documentation/core/info/modules/. If you have already');
102
+ console.log('downloaded this module, ensure that the SDK is able to find the required files');
103
+ console.log('using the PDFNet.addResourceSearchPath() function.\n');
104
+ }
105
+ else
106
+ {
107
+ try {
108
+ // Extract document structure as a JSON file
109
+ console.log('Extract document structure as a JSON file');
110
+
111
+ let outputFile = outputPath + 'paragraphs_and_tables.json';
112
+ await PDFNet.DataExtractionModule.extractData(inputPath + 'paragraphs_and_tables.pdf', outputFile, PDFNet.DataExtractionModule.DataExtractionEngine.e_DocStructure);
113
+
114
+ console.log('Result saved in ' + outputFile);
115
+
116
+ ///////////////////////////////////////////////////////
117
+ // Extract document structure as a JSON string
118
+ console.log('Extract document structure as a JSON string');
119
+
120
+ outputFile = outputPath + 'tagged.json';
121
+ const json = await PDFNet.DataExtractionModule.extractDataAsString(inputPath + 'tagged.pdf', PDFNet.DataExtractionModule.DataExtractionEngine.e_DocStructure);
122
+ fs.writeFileSync(outputFile, json);
123
+
124
+ console.log('Result saved in ' + outputFile);
125
+ } catch (err) {
126
+ console.log(err);
127
+ }
128
+ }
129
+
130
+ //////////////////////////////////////////////////////////////////////////
131
+ // The following sample illustrates how to extract form fields from PDF documents.
132
+ //////////////////////////////////////////////////////////////////////////
133
+
134
+ // Test if the add-on is installed
135
+ if (!await PDFNet.DataExtractionModule.isModuleAvailable(PDFNet.DataExtractionModule.DataExtractionEngine.e_Form)) {
136
+ console.log('\nUnable to run Data Extraction: PDFTron SDK AIFormFieldExtractor module not available.');
137
+ console.log('---------------------------------------------------------------');
138
+ console.log('The Data Extraction suite is an optional add-on, available for download');
139
+ console.log('at https://www.pdftron.com/documentation/core/info/modules/. If you have already');
140
+ console.log('downloaded this module, ensure that the SDK is able to find the required files');
141
+ console.log('using the PDFNet.addResourceSearchPath() function.\n');
142
+ }
143
+ else
144
+ {
145
+ try {
146
+ // Extract form fields as a JSON file
147
+ console.log('Extract form fields as a JSON file');
148
+
149
+ let outputFile = outputPath + 'formfields-scanned.json';
150
+ await PDFNet.DataExtractionModule.extractData(inputPath + 'formfields-scanned.pdf', outputFile, PDFNet.DataExtractionModule.DataExtractionEngine.e_Form);
151
+
152
+ console.log('Result saved in ' + outputFile);
153
+
154
+ ///////////////////////////////////////////////////////
155
+ // Extract form fields as a JSON string
156
+ console.log('Extract form fields as a JSON string');
157
+
158
+ outputFile = outputPath + 'formfields.json';
159
+ const json = await PDFNet.DataExtractionModule.extractDataAsString(inputPath + 'formfields.pdf', PDFNet.DataExtractionModule.DataExtractionEngine.e_Form);
160
+ fs.writeFileSync(outputFile, json);
161
+
162
+ console.log('Result saved in ' + outputFile);
163
+ } catch (err) {
164
+ console.log(err);
165
+ }
166
+ }
167
+
168
+ //////////////////////////////////////////////////////////////////////////
169
+
170
+ console.log('Done.');
171
+ };
172
+
173
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
174
+ console.log('Error: ' + JSON.stringify(error));
175
+ }).then(function () { return PDFNet.shutdown(); });
176
+ };
177
+ exports.runDataExtractionTest();
178
+ })(exports);
179
+ // eslint-disable-next-line spaced-comment
180
+ //# sourceURL=DataExtractionTest.js
@@ -0,0 +1,180 @@
1
+ //---------------------------------------------------------------------------------------
2
+ // Copyright (c) 2001-2023 by PDFTron Systems Inc. All Rights Reserved.
3
+ // Consult legal.txt regarding legal and license information.
4
+ //---------------------------------------------------------------------------------------
5
+
6
+ //---------------------------------------------------------------------------------------
7
+ // The Data Extraction suite is an optional PDFNet add-on collection that can be used to
8
+ // extract various types of data from PDF documents.
9
+ //
10
+ // The PDFTron SDK Data Extraction suite can be downloaded from http://www.pdftron.com/
11
+ //---------------------------------------------------------------------------------------
12
+
13
+ const fs = require('fs');
14
+ const { PDFNet } = require('../../../lib/pdfnet.js');
15
+ const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
16
+
17
+ ((exports) => {
18
+ 'use strict';
19
+
20
+ exports.runDataExtractionTest = () => {
21
+
22
+ const main = async () => {
23
+
24
+ const inputPath = '../../TestFiles/';
25
+ const outputPath = '../../TestFiles/Output/';
26
+
27
+ //////////////////////////////////////////////////////////////////////////
28
+
29
+ await PDFNet.addResourceSearchPath('../../../lib/');
30
+
31
+ //////////////////////////////////////////////////////////////////////////
32
+ // The following sample illustrates how to extract tables from PDF documents.
33
+ //////////////////////////////////////////////////////////////////////////
34
+
35
+ // Test if the add-on is installed
36
+ if (!await PDFNet.DataExtractionModule.isModuleAvailable(PDFNet.DataExtractionModule.DataExtractionEngine.e_Tabular)) {
37
+ console.log('\nUnable to run Data Extraction: PDFTron SDK Tabular Data module not available.');
38
+ console.log('---------------------------------------------------------------');
39
+ console.log('The Data Extraction suite is an optional add-on, available for download');
40
+ console.log('at https://www.pdftron.com/documentation/core/info/modules/. If you have already');
41
+ console.log('downloaded this module, ensure that the SDK is able to find the required files');
42
+ console.log('using the PDFNet.addResourceSearchPath() function.\n');
43
+ }
44
+ else
45
+ {
46
+ try {
47
+ // Extract tabular data as a JSON file
48
+ console.log('Extract tabular data as a JSON file');
49
+
50
+ let outputFile = outputPath + 'table.json';
51
+ await PDFNet.DataExtractionModule.extractData(inputPath + 'table.pdf', outputFile, PDFNet.DataExtractionModule.DataExtractionEngine.e_Tabular);
52
+
53
+ console.log('Result saved in ' + outputFile);
54
+
55
+ ///////////////////////////////////////////////////////
56
+ // Extract tabular data as a JSON string
57
+ console.log('Extract tabular data as a JSON string');
58
+
59
+ outputFile = outputPath + 'financial.json';
60
+ const json = await PDFNet.DataExtractionModule.extractDataAsString(inputPath + 'financial.pdf', PDFNet.DataExtractionModule.DataExtractionEngine.e_Tabular);
61
+ fs.writeFileSync(outputFile, json);
62
+
63
+ console.log('Result saved in ' + outputFile);
64
+
65
+ ///////////////////////////////////////////////////////
66
+ // Extract tabular data as an XLSX file
67
+ console.log('Extract tabular data as an XLSX file');
68
+
69
+ outputFile = outputPath + 'table.xlsx';
70
+ await PDFNet.DataExtractionModule.extractToXSLX(inputPath + 'table.pdf', outputFile);
71
+
72
+ console.log('Result saved in ' + outputFile);
73
+
74
+ ///////////////////////////////////////////////////////
75
+ // Extract tabular data as an XLSX stream (also known as filter)
76
+ console.log('Extract tabular data as an XLSX stream');
77
+
78
+ outputFile = outputPath + 'financial.xlsx';
79
+ const outputXlsxStream = await PDFNet.Filter.createMemoryFilter(0, false);
80
+ const options = new PDFNet.DataExtractionModule.DataExtractionOptions();
81
+ options.setPages("1"); // page 1
82
+ await PDFNet.DataExtractionModule.extractToXSLXWithFilter(inputPath + 'financial.pdf', outputXlsxStream, options);
83
+ outputXlsxStream.memoryFilterSetAsInputFilter();
84
+ outputXlsxStream.writeToFile(outputFile, false);
85
+
86
+ console.log('Result saved in ' + outputFile);
87
+ } catch (err) {
88
+ console.log(err);
89
+ }
90
+ }
91
+
92
+ //////////////////////////////////////////////////////////////////////////
93
+ // The following sample illustrates how to extract document structure from PDF documents.
94
+ //////////////////////////////////////////////////////////////////////////
95
+
96
+ // Test if the add-on is installed
97
+ if (!await PDFNet.DataExtractionModule.isModuleAvailable(PDFNet.DataExtractionModule.DataExtractionEngine.e_DocStructure)) {
98
+ console.log('\nUnable to run Data Extraction: PDFTron SDK Structured Output module not available.');
99
+ console.log('---------------------------------------------------------------');
100
+ console.log('The Data Extraction suite is an optional add-on, available for download');
101
+ console.log('at https://www.pdftron.com/documentation/core/info/modules/. If you have already');
102
+ console.log('downloaded this module, ensure that the SDK is able to find the required files');
103
+ console.log('using the PDFNet.addResourceSearchPath() function.\n');
104
+ }
105
+ else
106
+ {
107
+ try {
108
+ // Extract document structure as a JSON file
109
+ console.log('Extract document structure as a JSON file');
110
+
111
+ let outputFile = outputPath + 'paragraphs_and_tables.json';
112
+ await PDFNet.DataExtractionModule.extractData(inputPath + 'paragraphs_and_tables.pdf', outputFile, PDFNet.DataExtractionModule.DataExtractionEngine.e_DocStructure);
113
+
114
+ console.log('Result saved in ' + outputFile);
115
+
116
+ ///////////////////////////////////////////////////////
117
+ // Extract document structure as a JSON string
118
+ console.log('Extract document structure as a JSON string');
119
+
120
+ outputFile = outputPath + 'tagged.json';
121
+ const json = await PDFNet.DataExtractionModule.extractDataAsString(inputPath + 'tagged.pdf', PDFNet.DataExtractionModule.DataExtractionEngine.e_DocStructure);
122
+ fs.writeFileSync(outputFile, json);
123
+
124
+ console.log('Result saved in ' + outputFile);
125
+ } catch (err) {
126
+ console.log(err);
127
+ }
128
+ }
129
+
130
+ //////////////////////////////////////////////////////////////////////////
131
+ // The following sample illustrates how to extract form fields from PDF documents.
132
+ //////////////////////////////////////////////////////////////////////////
133
+
134
+ // Test if the add-on is installed
135
+ if (!await PDFNet.DataExtractionModule.isModuleAvailable(PDFNet.DataExtractionModule.DataExtractionEngine.e_Form)) {
136
+ console.log('\nUnable to run Data Extraction: PDFTron SDK AIFormFieldExtractor module not available.');
137
+ console.log('---------------------------------------------------------------');
138
+ console.log('The Data Extraction suite is an optional add-on, available for download');
139
+ console.log('at https://www.pdftron.com/documentation/core/info/modules/. If you have already');
140
+ console.log('downloaded this module, ensure that the SDK is able to find the required files');
141
+ console.log('using the PDFNet.addResourceSearchPath() function.\n');
142
+ }
143
+ else
144
+ {
145
+ try {
146
+ // Extract form fields as a JSON file
147
+ console.log('Extract form fields as a JSON file');
148
+
149
+ let outputFile = outputPath + 'formfields-scanned.json';
150
+ await PDFNet.DataExtractionModule.extractData(inputPath + 'formfields-scanned.pdf', outputFile, PDFNet.DataExtractionModule.DataExtractionEngine.e_Form);
151
+
152
+ console.log('Result saved in ' + outputFile);
153
+
154
+ ///////////////////////////////////////////////////////
155
+ // Extract form fields as a JSON string
156
+ console.log('Extract form fields as a JSON string');
157
+
158
+ outputFile = outputPath + 'formfields.json';
159
+ const json = await PDFNet.DataExtractionModule.extractDataAsString(inputPath + 'formfields.pdf', PDFNet.DataExtractionModule.DataExtractionEngine.e_Form);
160
+ fs.writeFileSync(outputFile, json);
161
+
162
+ console.log('Result saved in ' + outputFile);
163
+ } catch (err) {
164
+ console.log(err);
165
+ }
166
+ }
167
+
168
+ //////////////////////////////////////////////////////////////////////////
169
+
170
+ console.log('Done.');
171
+ };
172
+
173
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
174
+ console.log('Error: ' + JSON.stringify(error));
175
+ }).then(function () { return PDFNet.shutdown(); });
176
+ };
177
+ exports.runDataExtractionTest();
178
+ })(exports);
179
+ // eslint-disable-next-line spaced-comment
180
+ //# sourceURL=DataExtractionTest.js
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node DataExtractionTest.js