@pdftron/pdfnet-node-samples 9.4.2 → 9.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -1,235 +1,235 @@
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
- 'use strict';
12
-
13
- //---------------------------------------------------------------------------------------
14
- // The following sample illustrates how to use OCR module
15
- //---------------------------------------------------------------------------------------
16
- exports.runOCRTest = () => {
17
- const main = async () => {
18
- try {
19
-
20
- PDFNet.addResourceSearchPath('../../lib/');
21
-
22
- const useIRIS = await PDFNet.OCRModule.isIRISModuleAvailable();
23
- if (!(await PDFNet.OCRModule.isModuleAvailable())) {
24
- console.log('\nUnable to run OCRTest: PDFTron SDK OCR module not available.');
25
- console.log('---------------------------------------------------------------');
26
- console.log('The OCR module is an optional add-on, available for download');
27
- console.log('at http://www.pdftron.com/. If you have already downloaded this');
28
- console.log('module, ensure that the SDK is able to find the required files');
29
- console.log('using the PDFNet.addResourceSearchPath() function.\n');
30
-
31
- return;
32
- }
33
-
34
- // Relative path to the folder containing test files.
35
- const input_path = '../TestFiles/OCR/';
36
- const output_path = '../TestFiles/Output/';
37
-
38
- //--------------------------------------------------------------------------------
39
- // Example 1) Process image without specifying options, default language - English - is used
40
- try {
41
-
42
- // A) Setup empty destination doc
43
- const doc = await PDFNet.PDFDoc.create();
44
-
45
- await doc.initSecurityHandler();
46
-
47
- const opts = new PDFNet.OCRModule.OCROptions();
48
- if(useIRIS) opts.setOCREngine('iris');
49
-
50
- // B) Run OCR on the .png with options
51
- await PDFNet.OCRModule.imageToPDF(doc, input_path + 'psychomachia_excerpt.png', opts);
52
-
53
- // C) check the result
54
- await doc.save(output_path + 'psychomachia_excerpt.pdf', 0);
55
-
56
- console.log('Example 1: psychomachia_excerpt.png');
57
-
58
- } catch (err) {
59
- console.log(err);
60
- }
61
-
62
- //--------------------------------------------------------------------------------
63
- // Example 2) Process document using multiple languages
64
- try {
65
- // A) Setup empty destination doc
66
- const doc = await PDFNet.PDFDoc.create();
67
- await doc.initSecurityHandler();
68
-
69
- // B) Setup options with multiple target languages, English will always be considered as secondary language
70
- const opts = new PDFNet.OCRModule.OCROptions();
71
- if(useIRIS) opts.setOCREngine('iris');
72
- opts.addLang('rus');
73
- opts.addLang('deu');
74
-
75
- // C) Run OCR on the .jpg with options
76
- await PDFNet.OCRModule.imageToPDF(doc, input_path + 'multi_lang.jpg', opts);
77
-
78
- // D) check the result
79
- await doc.save(output_path + 'multi_lang.pdf', 0);
80
-
81
- console.log('Example 2: multi_lang.jpg');
82
- } catch (err) {
83
- console.log(err);
84
- }
85
-
86
- //--------------------------------------------------------------------------------
87
- // Example 3) Process a .pdf specifying a language - German - and ignore zone comprising a sidebar image
88
- try {
89
- // A) Open the .pdf document
90
- const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'german_kids_song.pdf');
91
- doc.initSecurityHandler();
92
-
93
- // B) Setup options with a single language and an ignore zone
94
- const opts = new PDFNet.OCRModule.OCROptions();
95
- if(useIRIS) opts.setOCREngine('iris');
96
- opts.addLang('deu');
97
-
98
- const ignore_zones = [];
99
- ignore_zones.push(new PDFNet.Rect(424, 163, 493, 730));
100
- opts.addIgnoreZonesForPage(ignore_zones, 1);
101
-
102
- // C) Run OCR on the .pdf with options
103
- await PDFNet.OCRModule.processPDF(doc, opts);
104
-
105
- // D) check the result
106
- await doc.save(output_path + 'german_kids_song.pdf', 0);
107
-
108
- console.log('Example 3: german_kids_song.pdf');
109
- } catch (err) {
110
- console.log(err);
111
- }
112
-
113
- //--------------------------------------------------------------------------------
114
- // Example 4) Process multipage tiff with text/ignore zones specified for each page, optionally provide English as the target language
115
- try {
116
- // A) Setup empty destination doc
117
- const doc = await PDFNet.PDFDoc.create();
118
- await doc.initSecurityHandler();
119
-
120
- // B) Setup options with a single language plus text/ignore zones
121
- const opts = new PDFNet.OCRModule.OCROptions();
122
- if(useIRIS) opts.setOCREngine('iris');
123
- opts.addLang('eng');
124
-
125
- var ignore_zones = [];
126
- // ignore signature box in the first 2 pages
127
- ignore_zones.push(new PDFNet.Rect(1492, 56, 2236, 432));
128
- opts.addIgnoreZonesForPage(ignore_zones, 1);
129
-
130
- ignore_zones = [];
131
- ignore_zones.push(new PDFNet.Rect(1492, 56, 2236, 432));
132
- opts.addIgnoreZonesForPage(ignore_zones, 2);
133
-
134
- // can use a combination of ignore and text boxes to focus on the page area of interest,
135
- // as ignore boxes are applied first, we remove the arrows before selecting part of the diagram
136
- ignore_zones = [];
137
- ignore_zones.push(new PDFNet.Rect(992, 1276, 1368, 1372));
138
- opts.addIgnoreZonesForPage(ignore_zones, 3);
139
-
140
-
141
- const text_zones = [];
142
- // we only have text zones selected in page 3
143
-
144
- // select horizontal BUFFER ZONE sign
145
- text_zones.push(new PDFNet.Rect(900, 2384, 1236, 2480));
146
- // select right vertical BUFFER ZONE sign
147
- text_zones.push(new PDFNet.Rect(1960, 1976, 2016, 2296));
148
- // select Lot No.
149
- text_zones.push(new PDFNet.Rect(696, 1028, 1196, 1128));
150
-
151
- // select part of the plan inside the BUFFER ZONE
152
- text_zones.push(new PDFNet.Rect(428, 1484, 1784, 2344));
153
- text_zones.push(new PDFNet.Rect(948, 1288, 1672, 1476));
154
- opts.addTextZonesForPage(text_zones, 3);
155
-
156
- // C) Run OCR on the .tif with options
157
- await PDFNet.OCRModule.imageToPDF(doc, input_path + 'bc_environment_protection.tif', opts);
158
-
159
- // D) check the result
160
- await doc.save(output_path + 'bc_environment_protection.pdf', 0);
161
-
162
- console.log('Example 4: bc_environment_protection.tif');
163
- } catch (err) {
164
- console.log(err);
165
- }
166
-
167
- //--------------------------------------------------------------------------------
168
- // Example 5) Alternative workflow for extracting OCR result JSON, postprocessing (e.g., removing words not in the dictionary or filtering special
169
- // out special characters), and finally applying modified OCR JSON to the source PDF document
170
- try {
171
- // A) Open the .pdf document
172
- const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'zero_value_test_no_text.pdf');
173
- await doc.initSecurityHandler();
174
-
175
- const opts = new PDFNet.OCRModule.OCROptions();
176
- if(useIRIS) opts.setOCREngine('iris');
177
-
178
- // B) Run OCR on the .pdf with default English language
179
- const json = await PDFNet.OCRModule.getOCRJsonFromPDF(doc, opts);
180
-
181
- // C) Post-processing step (whatever it might be)
182
- console.log('Have OCR result JSON, re-applying to PDF ');
183
-
184
- // D) Apply potentially modified OCR JSON to the PDF
185
- await PDFNet.OCRModule.applyOCRJsonToPDF(doc, json);
186
-
187
- // E) Check the result
188
- await doc.save(output_path + 'zero_value_test_no_text.pdf', 0);
189
-
190
- console.log('Example 5: extracting and applying OCR JSON from zero_value_test_no_text.pdf');
191
- } catch (err) {
192
- console.log(err);
193
- }
194
-
195
- //--------------------------------------------------------------------------------
196
- // Example 6) The postprocessing workflow has also an option of extracting OCR results in XML format, similar to the one used by TextExtractor
197
- try {
198
-
199
- // A) Setup empty destination doc
200
- const doc = await PDFNet.PDFDoc.create();
201
- await doc.initSecurityHandler();
202
-
203
- const opts = new PDFNet.OCRModule.OCROptions();
204
- if(useIRIS) opts.setOCREngine('iris');
205
-
206
- // B) Run OCR on the .tif with default English language, extracting OCR results in XML format. Note that
207
- // in the process we convert the source image into PDF. We reuse this PDF document later to add hidden text layer to it.
208
- const xml = await PDFNet.OCRModule.getOCRXmlFromImage(doc, input_path + 'physics.tif', opts);
209
-
210
- // C) Post-processing step (whatever it might be)
211
- console.log('Have OCR result XML, re-applying to PDF');
212
-
213
- // D) Apply potentially modified OCR XML to the PDF
214
- await PDFNet.OCRModule.applyOCRXmlToPDF(doc, xml);
215
-
216
- // E) Check the result
217
- await doc.save(output_path + 'physics.pdf', 0);
218
-
219
- console.log('Example 6: extracting and applying OCR XML from physics.tif');
220
- } catch (err) {
221
- console.log(err);
222
- }
223
- console.log('Done.');
224
- } catch (err) {
225
- console.log(err);
226
- }
227
- };
228
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
229
- console.log('Error: ' + JSON.stringify(error));
230
- }).then(function(){ return PDFNet.shutdown(); });
231
- };
232
- exports.runOCRTest();
233
- })(exports);
234
- // eslint-disable-next-line spaced-comment
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
+ const { PDFNet } = require('@pdftron/pdfnet-node');
8
+ const PDFTronLicense = require('../LicenseKey/LicenseKey');
9
+
10
+ ((exports) => {
11
+ 'use strict';
12
+
13
+ //---------------------------------------------------------------------------------------
14
+ // The following sample illustrates how to use OCR module
15
+ //---------------------------------------------------------------------------------------
16
+ exports.runOCRTest = () => {
17
+ const main = async () => {
18
+ try {
19
+
20
+ PDFNet.addResourceSearchPath('../../lib/');
21
+
22
+ const useIRIS = await PDFNet.OCRModule.isIRISModuleAvailable();
23
+ if (!(await PDFNet.OCRModule.isModuleAvailable())) {
24
+ console.log('\nUnable to run OCRTest: PDFTron SDK OCR module not available.');
25
+ console.log('---------------------------------------------------------------');
26
+ console.log('The OCR module is an optional add-on, available for download');
27
+ console.log('at http://www.pdftron.com/. If you have already downloaded this');
28
+ console.log('module, ensure that the SDK is able to find the required files');
29
+ console.log('using the PDFNet.addResourceSearchPath() function.\n');
30
+
31
+ return;
32
+ }
33
+
34
+ // Relative path to the folder containing test files.
35
+ const input_path = '../TestFiles/OCR/';
36
+ const output_path = '../TestFiles/Output/';
37
+
38
+ //--------------------------------------------------------------------------------
39
+ // Example 1) Process image without specifying options, default language - English - is used
40
+ try {
41
+
42
+ // A) Setup empty destination doc
43
+ const doc = await PDFNet.PDFDoc.create();
44
+
45
+ await doc.initSecurityHandler();
46
+
47
+ const opts = new PDFNet.OCRModule.OCROptions();
48
+ if(useIRIS) opts.setOCREngine('iris');
49
+
50
+ // B) Run OCR on the .png with options
51
+ await PDFNet.OCRModule.imageToPDF(doc, input_path + 'psychomachia_excerpt.png', opts);
52
+
53
+ // C) check the result
54
+ await doc.save(output_path + 'psychomachia_excerpt.pdf', 0);
55
+
56
+ console.log('Example 1: psychomachia_excerpt.png');
57
+
58
+ } catch (err) {
59
+ console.log(err);
60
+ }
61
+
62
+ //--------------------------------------------------------------------------------
63
+ // Example 2) Process document using multiple languages
64
+ try {
65
+ // A) Setup empty destination doc
66
+ const doc = await PDFNet.PDFDoc.create();
67
+ await doc.initSecurityHandler();
68
+
69
+ // B) Setup options with multiple target languages, English will always be considered as secondary language
70
+ const opts = new PDFNet.OCRModule.OCROptions();
71
+ if(useIRIS) opts.setOCREngine('iris');
72
+ opts.addLang('rus');
73
+ opts.addLang('deu');
74
+
75
+ // C) Run OCR on the .jpg with options
76
+ await PDFNet.OCRModule.imageToPDF(doc, input_path + 'multi_lang.jpg', opts);
77
+
78
+ // D) check the result
79
+ await doc.save(output_path + 'multi_lang.pdf', 0);
80
+
81
+ console.log('Example 2: multi_lang.jpg');
82
+ } catch (err) {
83
+ console.log(err);
84
+ }
85
+
86
+ //--------------------------------------------------------------------------------
87
+ // Example 3) Process a .pdf specifying a language - German - and ignore zone comprising a sidebar image
88
+ try {
89
+ // A) Open the .pdf document
90
+ const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'german_kids_song.pdf');
91
+ doc.initSecurityHandler();
92
+
93
+ // B) Setup options with a single language and an ignore zone
94
+ const opts = new PDFNet.OCRModule.OCROptions();
95
+ if(useIRIS) opts.setOCREngine('iris');
96
+ opts.addLang('deu');
97
+
98
+ const ignore_zones = [];
99
+ ignore_zones.push(new PDFNet.Rect(424, 163, 493, 730));
100
+ opts.addIgnoreZonesForPage(ignore_zones, 1);
101
+
102
+ // C) Run OCR on the .pdf with options
103
+ await PDFNet.OCRModule.processPDF(doc, opts);
104
+
105
+ // D) check the result
106
+ await doc.save(output_path + 'german_kids_song.pdf', 0);
107
+
108
+ console.log('Example 3: german_kids_song.pdf');
109
+ } catch (err) {
110
+ console.log(err);
111
+ }
112
+
113
+ //--------------------------------------------------------------------------------
114
+ // Example 4) Process multipage tiff with text/ignore zones specified for each page, optionally provide English as the target language
115
+ try {
116
+ // A) Setup empty destination doc
117
+ const doc = await PDFNet.PDFDoc.create();
118
+ await doc.initSecurityHandler();
119
+
120
+ // B) Setup options with a single language plus text/ignore zones
121
+ const opts = new PDFNet.OCRModule.OCROptions();
122
+ if(useIRIS) opts.setOCREngine('iris');
123
+ opts.addLang('eng');
124
+
125
+ var ignore_zones = [];
126
+ // ignore signature box in the first 2 pages
127
+ ignore_zones.push(new PDFNet.Rect(1492, 56, 2236, 432));
128
+ opts.addIgnoreZonesForPage(ignore_zones, 1);
129
+
130
+ ignore_zones = [];
131
+ ignore_zones.push(new PDFNet.Rect(1492, 56, 2236, 432));
132
+ opts.addIgnoreZonesForPage(ignore_zones, 2);
133
+
134
+ // can use a combination of ignore and text boxes to focus on the page area of interest,
135
+ // as ignore boxes are applied first, we remove the arrows before selecting part of the diagram
136
+ ignore_zones = [];
137
+ ignore_zones.push(new PDFNet.Rect(992, 1276, 1368, 1372));
138
+ opts.addIgnoreZonesForPage(ignore_zones, 3);
139
+
140
+
141
+ const text_zones = [];
142
+ // we only have text zones selected in page 3
143
+
144
+ // select horizontal BUFFER ZONE sign
145
+ text_zones.push(new PDFNet.Rect(900, 2384, 1236, 2480));
146
+ // select right vertical BUFFER ZONE sign
147
+ text_zones.push(new PDFNet.Rect(1960, 1976, 2016, 2296));
148
+ // select Lot No.
149
+ text_zones.push(new PDFNet.Rect(696, 1028, 1196, 1128));
150
+
151
+ // select part of the plan inside the BUFFER ZONE
152
+ text_zones.push(new PDFNet.Rect(428, 1484, 1784, 2344));
153
+ text_zones.push(new PDFNet.Rect(948, 1288, 1672, 1476));
154
+ opts.addTextZonesForPage(text_zones, 3);
155
+
156
+ // C) Run OCR on the .tif with options
157
+ await PDFNet.OCRModule.imageToPDF(doc, input_path + 'bc_environment_protection.tif', opts);
158
+
159
+ // D) check the result
160
+ await doc.save(output_path + 'bc_environment_protection.pdf', 0);
161
+
162
+ console.log('Example 4: bc_environment_protection.tif');
163
+ } catch (err) {
164
+ console.log(err);
165
+ }
166
+
167
+ //--------------------------------------------------------------------------------
168
+ // Example 5) Alternative workflow for extracting OCR result JSON, postprocessing (e.g., removing words not in the dictionary or filtering special
169
+ // out special characters), and finally applying modified OCR JSON to the source PDF document
170
+ try {
171
+ // A) Open the .pdf document
172
+ const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'zero_value_test_no_text.pdf');
173
+ await doc.initSecurityHandler();
174
+
175
+ const opts = new PDFNet.OCRModule.OCROptions();
176
+ if(useIRIS) opts.setOCREngine('iris');
177
+
178
+ // B) Run OCR on the .pdf with default English language
179
+ const json = await PDFNet.OCRModule.getOCRJsonFromPDF(doc, opts);
180
+
181
+ // C) Post-processing step (whatever it might be)
182
+ console.log('Have OCR result JSON, re-applying to PDF ');
183
+
184
+ // D) Apply potentially modified OCR JSON to the PDF
185
+ await PDFNet.OCRModule.applyOCRJsonToPDF(doc, json);
186
+
187
+ // E) Check the result
188
+ await doc.save(output_path + 'zero_value_test_no_text.pdf', 0);
189
+
190
+ console.log('Example 5: extracting and applying OCR JSON from zero_value_test_no_text.pdf');
191
+ } catch (err) {
192
+ console.log(err);
193
+ }
194
+
195
+ //--------------------------------------------------------------------------------
196
+ // Example 6) The postprocessing workflow has also an option of extracting OCR results in XML format, similar to the one used by TextExtractor
197
+ try {
198
+
199
+ // A) Setup empty destination doc
200
+ const doc = await PDFNet.PDFDoc.create();
201
+ await doc.initSecurityHandler();
202
+
203
+ const opts = new PDFNet.OCRModule.OCROptions();
204
+ if(useIRIS) opts.setOCREngine('iris');
205
+
206
+ // B) Run OCR on the .tif with default English language, extracting OCR results in XML format. Note that
207
+ // in the process we convert the source image into PDF. We reuse this PDF document later to add hidden text layer to it.
208
+ const xml = await PDFNet.OCRModule.getOCRXmlFromImage(doc, input_path + 'physics.tif', opts);
209
+
210
+ // C) Post-processing step (whatever it might be)
211
+ console.log('Have OCR result XML, re-applying to PDF');
212
+
213
+ // D) Apply potentially modified OCR XML to the PDF
214
+ await PDFNet.OCRModule.applyOCRXmlToPDF(doc, xml);
215
+
216
+ // E) Check the result
217
+ await doc.save(output_path + 'physics.pdf', 0);
218
+
219
+ console.log('Example 6: extracting and applying OCR XML from physics.tif');
220
+ } catch (err) {
221
+ console.log(err);
222
+ }
223
+ console.log('Done.');
224
+ } catch (err) {
225
+ console.log(err);
226
+ }
227
+ };
228
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
229
+ console.log('Error: ' + JSON.stringify(error));
230
+ }).then(function(){ return PDFNet.shutdown(); });
231
+ };
232
+ exports.runOCRTest();
233
+ })(exports);
234
+ // eslint-disable-next-line spaced-comment
235
235
  //# sourceURL=OCRTest.js
@@ -0,0 +1,79 @@
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
8
+ // to convert MS Office files to PDF and replace templated tags present in the document
9
+ // with content supplied via json
10
+ //
11
+ // For a detailed specification of the template format and supported features,
12
+ // see: https://www.pdftron.com/documentation/core/guides/generate-via-template/data-model/
13
+ //
14
+ // This conversion is performed entirely within the PDFNet and has *no*
15
+ // external or system dependencies -- Conversion results will be
16
+ // the same whether on Windows, Linux or Android.
17
+ //
18
+ // Please contact us if you have any questions.
19
+ //------------------------------------------------------------------------------
20
+
21
+ const { PDFNet } = require('../../../lib/pdfnet.js');
22
+ const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
23
+
24
+ ((exports) => {
25
+ 'use strict';
26
+
27
+ exports.runOfficeTemplateTest = () => {
28
+
29
+ const inputPath = '../../TestFiles/';
30
+ const outputPath = inputPath + 'Output/';
31
+ const inputFilename = 'SYH_Letter.docx'
32
+ const outputFilename = 'SYH_Letter.pdf'
33
+
34
+ const main = async () => {
35
+
36
+ PDFNet.addResourceSearchPath('../../Resources');
37
+
38
+ try {
39
+ const options = new PDFNet.Convert.OfficeToPDFOptions();
40
+
41
+ const json = JSON.stringify({
42
+ 'dest_given_name': 'Janice N.',
43
+ 'dest_street_address': "187 Duizelstraat",
44
+ 'dest_surname': 'Symonds',
45
+ 'dest_title': 'Ms.',
46
+ 'land_location': '225 Parc St., Rochelle, QC ',
47
+ 'lease_problem': 'According to the city records, the lease was initiated in September 2010 and never terminated',
48
+ 'logo': { 'image_url': inputPath + 'logo_red.png', 'width' : 64, 'height': 64 },
49
+ 'sender_name': 'Arnold Smith'
50
+ });
51
+
52
+ // Create a TemplateDocument object from an input office file.
53
+ const templateDoc = await PDFNet.Convert.createOfficeTemplateWithPath(inputPath + inputFilename, options);
54
+
55
+ // Fill the template with data from a JSON string, producing a PDF document.
56
+ const pdfdoc = await templateDoc.fillTemplateJson(json);
57
+
58
+ // Save the PDF to a file.
59
+ await pdfdoc.save(outputPath + outputFilename, PDFNet.SDFDoc.SaveOptions.e_linearized);
60
+
61
+ // And we're done!
62
+ console.log('Saved ' + outputFilename);
63
+
64
+ } catch (err) {
65
+ console.log(err);
66
+ }
67
+
68
+ console.log('Done.');
69
+ };
70
+
71
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
72
+ console.log('Error: ' + JSON.stringify(error));
73
+ }).then(function () { return PDFNet.shutdown(); });
74
+
75
+ };
76
+ exports.runOfficeTemplateTest();
77
+ })(exports);
78
+ // eslint-disable-next-line spaced-comment
79
+ //# sourceURL=OfficeTemplateTest.js
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node OfficeTemplateTest.js