@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,123 @@
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 HTML.
9
+ //
10
+ // There are two HTML modules and one of them is an optional PDFNet Add-on.
11
+ // 1. The built-in HTML module is used to convert PDF documents to fixed-position HTML
12
+ // documents.
13
+ // 2. The optional Structured Output add-on module is used to convert PDF documents to
14
+ // HTML documents with text flowing across the browser window.
15
+ //
16
+ // The PDFTron SDK Structured Output module can be downloaded from
17
+ // https://www.pdftron.com/documentation/core/info/modules/
18
+ //
19
+ // Please contact us if you have any questions.
20
+ //---------------------------------------------------------------------------------------
21
+
22
+ const { PDFNet } = require('../../../lib/pdfnet.js');
23
+ const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
24
+
25
+ ((exports) => {
26
+ 'use strict';
27
+
28
+ exports.runPDF2HtmlTest = () => {
29
+
30
+ const main = async () => {
31
+
32
+ const inputPath = '../../TestFiles/';
33
+ const outputPath = '../../TestFiles/Output/';
34
+
35
+ //////////////////////////////////////////////////////////////////////////
36
+
37
+ try {
38
+ // Convert PDF document to HTML with fixed positioning option turned on (default)
39
+ console.log('Converting PDF to HTML with fixed positioning option turned on (default)');
40
+
41
+ const outputFile = outputPath + 'paragraphs_and_tables_fixed_positioning';
42
+
43
+ // Convert PDF to HTML
44
+ await PDFNet.Convert.fileToHtml(inputPath + 'paragraphs_and_tables.pdf', outputFile);
45
+
46
+ console.log('Result saved in ' + outputFile);
47
+ } catch (err) {
48
+ console.log(err);
49
+ }
50
+
51
+ //////////////////////////////////////////////////////////////////////////
52
+
53
+ await PDFNet.addResourceSearchPath('../../../lib/');
54
+
55
+ if (!await PDFNet.StructuredOutputModule.isModuleAvailable()) {
56
+ console.log('\nUnable to run part of the sample: PDFTron SDK Structured Output module not available.');
57
+ console.log('---------------------------------------------------------------');
58
+ console.log('The Structured Output module is an optional add-on, available for download');
59
+ console.log('at https://www.pdftron.com/documentation/core/info/modules/. If you have already');
60
+ console.log('downloaded this module, ensure that the SDK is able to find the required files');
61
+ console.log('using the PDFNet::AddResourceSearchPath() function.\n');
62
+
63
+ return;
64
+ }
65
+
66
+ //////////////////////////////////////////////////////////////////////////
67
+
68
+ try {
69
+ // Convert PDF document to HTML with reflow full option turned on (1)
70
+ console.log('Converting PDF to HTML with reflow full option turned on (1)');
71
+
72
+ const outputFile = outputPath + 'paragraphs_and_tables_reflow_full.html';
73
+
74
+ const htmlOutputOptions = new PDFNet.Convert.HTMLOutputOptions();
75
+
76
+ // Set e_reflow_full content reflow setting
77
+ htmlOutputOptions.setContentReflowSetting(PDFNet.Convert.HTMLOutputOptions.ContentReflowSetting.e_reflow_full);
78
+
79
+ // Convert PDF to HTML
80
+ await PDFNet.Convert.fileToHtml(inputPath + 'paragraphs_and_tables.pdf', outputFile, htmlOutputOptions);
81
+
82
+ console.log('Result saved in ' + outputFile);
83
+ } catch (err) {
84
+ console.log(err);
85
+ }
86
+
87
+ //////////////////////////////////////////////////////////////////////////
88
+
89
+ try {
90
+ // Convert PDF document to HTML with reflow full option turned on (only converting the first page) (2)
91
+ console.log('Converting PDF to HTML with reflow full option turned on (only converting the first page) (2)');
92
+
93
+ const outputFile = outputPath + 'paragraphs_and_tables_reflow_full_first_page.html';
94
+
95
+ const htmlOutputOptions = new PDFNet.Convert.HTMLOutputOptions();
96
+
97
+ // Set e_reflow_full content reflow setting
98
+ htmlOutputOptions.setContentReflowSetting(PDFNet.Convert.HTMLOutputOptions.ContentReflowSetting.e_reflow_full);
99
+
100
+ // Convert only the first page
101
+ htmlOutputOptions.setPages(1, 1);
102
+
103
+ // Convert PDF to HTML
104
+ await PDFNet.Convert.fileToHtml(inputPath + 'paragraphs_and_tables.pdf', outputFile, htmlOutputOptions);
105
+
106
+ console.log('Result saved in ' + outputFile);
107
+ } catch (err) {
108
+ console.log(err);
109
+ }
110
+
111
+ //////////////////////////////////////////////////////////////////////////
112
+
113
+ console.log('Done.');
114
+ };
115
+
116
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
117
+ console.log('Error: ' + JSON.stringify(error));
118
+ }).then(function () { return PDFNet.shutdown(); });
119
+ };
120
+ exports.runPDF2HtmlTest();
121
+ })(exports);
122
+ // eslint-disable-next-line spaced-comment
123
+ //# sourceURL=PDF2HtmlTest.js
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node PDF2HtmlTest.js
@@ -1,5 +1,5 @@
1
1
  //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2022 by PDFTron Systems Inc. All Rights Reserved.
2
+ // Copyright (c) 2001-2023 by PDFTron Systems Inc. All Rights Reserved.
3
3
  // Consult legal.txt regarding legal and license information.
4
4
  //---------------------------------------------------------------------------------------
5
5
 
@@ -0,0 +1,158 @@
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 Word, Excel and PowerPoint.
9
+ //
10
+ // The Structured Output module is an optional PDFNet Add-on that can be used to convert PDF
11
+ // and other documents into Word, Excel, PowerPoint and HTML format.
12
+ //
13
+ // The PDFTron SDK Structured Output module can be downloaded from
14
+ // https://www.pdftron.com/documentation/core/info/modules/
15
+ //
16
+ // Please contact us if you have any questions.
17
+ //---------------------------------------------------------------------------------------
18
+
19
+ const { PDFNet } = require('../../../lib/pdfnet.js');
20
+ const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
21
+
22
+ ((exports) => {
23
+ 'use strict';
24
+
25
+ exports.runPDF2OfficeTest = () => {
26
+
27
+ const main = async () => {
28
+
29
+ const inputPath = '../../TestFiles/';
30
+ const outputPath = '../../TestFiles/Output/';
31
+
32
+ //////////////////////////////////////////////////////////////////////////
33
+
34
+ await PDFNet.addResourceSearchPath('../../../lib/');
35
+
36
+ if (!await PDFNet.StructuredOutputModule.isModuleAvailable()) {
37
+ console.log('\nUnable to run the sample: PDFTron SDK Structured Output module not available.');
38
+ console.log('---------------------------------------------------------------');
39
+ console.log('The Structured Output module 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
+ return;
45
+ }
46
+
47
+ //////////////////////////////////////////////////////////////////////////
48
+
49
+ try {
50
+ // Convert PDF document to Word
51
+ console.log('Converting PDF to Word');
52
+
53
+ const outputFile = outputPath + 'paragraphs_and_tables.docx';
54
+
55
+ await PDFNet.Convert.fileToWord(inputPath + 'paragraphs_and_tables.pdf', outputFile);
56
+
57
+ console.log('Result saved in ' + outputFile);
58
+ } catch (err) {
59
+ console.log(err);
60
+ }
61
+
62
+ try {
63
+ // Convert PDF document to Word with options
64
+ console.log('Converting PDF to Word with options');
65
+
66
+ const outputFile = outputPath + 'paragraphs_and_tables_first_page.docx';
67
+
68
+ const wordOutputOptions = new PDFNet.Convert.WordOutputOptions();
69
+
70
+ // Convert only the first page
71
+ wordOutputOptions.setPages(1, 1);
72
+
73
+ await PDFNet.Convert.fileToWord(inputPath + 'paragraphs_and_tables.pdf', outputFile, wordOutputOptions);
74
+
75
+ console.log('Result saved in ' + outputFile);
76
+ } catch (err) {
77
+ console.log(err);
78
+ }
79
+
80
+ //////////////////////////////////////////////////////////////////////////
81
+
82
+ try {
83
+ // Convert PDF document to Excel
84
+ console.log('Converting PDF to Excel');
85
+
86
+ const outputFile = outputPath + 'paragraphs_and_tables.xlsx';
87
+
88
+ await PDFNet.Convert.fileToExcel(inputPath + 'paragraphs_and_tables.pdf', outputFile);
89
+
90
+ console.log('Result saved in ' + outputFile);
91
+ } catch (err) {
92
+ console.log(err);
93
+ }
94
+
95
+ try {
96
+ // Convert PDF document to Excel with options
97
+ console.log('Converting PDF to Excel with options');
98
+
99
+ const outputFile = outputPath + 'paragraphs_and_tables_second_page.xlsx';
100
+
101
+ const excelOutputOptions = new PDFNet.Convert.ExcelOutputOptions();
102
+
103
+ // Convert only the second page
104
+ excelOutputOptions.setPages(2, 2);
105
+
106
+ await PDFNet.Convert.fileToExcel(inputPath + 'paragraphs_and_tables.pdf', outputFile, excelOutputOptions);
107
+
108
+ console.log('Result saved in ' + outputFile);
109
+ } catch (err) {
110
+ console.log(err);
111
+ }
112
+
113
+ //////////////////////////////////////////////////////////////////////////
114
+
115
+ try {
116
+ // Convert PDF document to PowerPoint
117
+ console.log('Converting PDF to PowerPoint');
118
+
119
+ const outputFile = outputPath + 'paragraphs_and_tables.pptx';
120
+
121
+ await PDFNet.Convert.fileToPowerPoint(inputPath + 'paragraphs_and_tables.pdf', outputFile);
122
+
123
+ console.log('Result saved in ' + outputFile);
124
+ } catch (err) {
125
+ console.log(err);
126
+ }
127
+
128
+ try {
129
+ // Convert PDF document to PowerPoint with options
130
+ console.log('Converting PDF to PowerPoint with options');
131
+
132
+ const outputFile = outputPath + 'paragraphs_and_tables_first_page.pptx';
133
+
134
+ const powerPointOutputOptions = new PDFNet.Convert.PowerPointOutputOptions();
135
+
136
+ // Convert only the first page
137
+ powerPointOutputOptions.setPages(1, 1);
138
+
139
+ await PDFNet.Convert.fileToPowerPoint(inputPath + 'paragraphs_and_tables.pdf', outputFile, powerPointOutputOptions);
140
+
141
+ console.log('Result saved in ' + outputFile);
142
+ } catch (err) {
143
+ console.log(err);
144
+ }
145
+
146
+ //////////////////////////////////////////////////////////////////////////
147
+
148
+ console.log('Done.');
149
+ };
150
+
151
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
152
+ console.log('Error: ' + JSON.stringify(error));
153
+ }).then(function () { return PDFNet.shutdown(); });
154
+ };
155
+ exports.runPDF2OfficeTest();
156
+ })(exports);
157
+ // eslint-disable-next-line spaced-comment
158
+ //# sourceURL=PDF2OfficeTest.js
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node PDF2OfficeTest.js
@@ -1,5 +1,5 @@
1
1
  //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2022 by PDFTron Systems Inc. All Rights Reserved.
2
+ // Copyright (c) 2001-2023 by PDFTron Systems Inc. All Rights Reserved.
3
3
  // Consult legal.txt regarding legal and license information.
4
4
  //---------------------------------------------------------------------------------------
5
5
 
@@ -0,0 +1,85 @@
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
+ const { PDFNet } = require('../../../lib/pdfnet.js');
7
+ const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
8
+
9
+ ((exports) => {
10
+
11
+ exports.runPDFA = () => {
12
+
13
+ const printResults = async (pdfa, filename) => {
14
+
15
+ const errorCount = await pdfa.getErrorCount();
16
+ if (errorCount === 0) {
17
+ console.log(filename + ': OK.');
18
+ } else {
19
+ console.log(filename + ' is NOT a valid PDFA.');
20
+ for (let i = 0; i < errorCount; i++) {
21
+ const errorCode = await pdfa.getError(i);
22
+ const errorMsg = await PDFNet.PDFACompliance.getPDFAErrorMessage(errorCode);
23
+ console.log(' - e_PDFA ' + errorCode + ': ' + errorMsg + '.');
24
+ const numRefs = await pdfa.getRefObjCount(errorCode);
25
+ if (numRefs > 0) {
26
+ const objs = [];
27
+ for (let j = 0; j < numRefs; j++) {
28
+ const objRef = await pdfa.getRefObj(errorCode, j);
29
+ objs.push(objRef);
30
+ }
31
+ console.log(' Objects: ' + objs.join(', '));
32
+ }
33
+ }
34
+ console.log('');
35
+ }
36
+ }
37
+
38
+ //---------------------------------------------------------------------------------------
39
+ // The following sample illustrates how to parse and check if a PDF document meets the
40
+ // PDFA standard, using the PDFACompliance class object.
41
+ //---------------------------------------------------------------------------------------
42
+ const main = async () => {
43
+ const inputPath = '../../TestFiles/';
44
+ const outputPath = inputPath + 'Output/';
45
+ await PDFNet.setColorManagement(); // Enable color management (required for PDFA validation).
46
+
47
+ //-----------------------------------------------------------
48
+ // Example 1: PDF/A Validation
49
+ //-----------------------------------------------------------
50
+ try {
51
+ const filename = 'newsletter.pdf';
52
+ /* The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number
53
+ of object numbers that are collected for particular error codes. The default value is 10
54
+ in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs. */
55
+ const pdfa = await PDFNet.PDFACompliance.createFromFile(false, inputPath + filename, '', PDFNet.PDFACompliance.Conformance.e_Level2B);
56
+ await printResults(pdfa, filename);
57
+ } catch (err) {
58
+ console.log(err);
59
+ }
60
+
61
+ //-----------------------------------------------------------
62
+ // Example 2: PDF/A Conversion
63
+ //-----------------------------------------------------------
64
+ try {
65
+ let filename = 'fish.pdf';
66
+ const pdfa = await PDFNet.PDFACompliance.createFromFile(true, inputPath + filename, '', PDFNet.PDFACompliance.Conformance.e_Level2B);
67
+ filename = 'pdfa.pdf';
68
+ await pdfa.saveAsFromFileName(outputPath + filename);
69
+
70
+ // Re-validate the document after the conversion...
71
+ const comp = await PDFNet.PDFACompliance.createFromFile(false, outputPath + filename, '', PDFNet.PDFACompliance.Conformance.e_Level2B);
72
+ await printResults(comp, filename);
73
+ } catch (err) {
74
+ console.log(err);
75
+ }
76
+
77
+ console.log('PDFACompliance test completed.')
78
+ };
79
+
80
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
81
+ };
82
+ exports.runPDFA();
83
+ })(exports);
84
+ // eslint-disable-next-line spaced-comment
85
+ //# sourceURL=PDFATest.js
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node PDFATest.js
@@ -1,5 +1,5 @@
1
1
  //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2022 by PDFTron Systems Inc. All Rights Reserved.
2
+ // Copyright (c) 2001-2023 by PDFTron Systems Inc. All Rights Reserved.
3
3
  // Consult legal.txt regarding legal and license information.
4
4
  //---------------------------------------------------------------------------------------
5
5
 
@@ -0,0 +1,85 @@
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
+ const fs = require('fs');
7
+ const { PDFNet } = require('../../../lib/pdfnet.js');
8
+ const PDFTronLicense = require('../../LicenseKey/NODEJS/LicenseKey');
9
+
10
+ ((exports) => {
11
+ 'use strict';
12
+
13
+ exports.runPDFDocMemoryTest = () => {
14
+ const main = async () => {
15
+ const outputPath = '../../TestFiles/Output/';
16
+
17
+ // The following sample illustrates how to read/write a PDF document from/to
18
+ // a memory buffer. This is useful for applications that work with dynamic PDF
19
+ // documents that don't need to be saved/read from a disk.
20
+ try {
21
+ // Read a PDF document in a memory buffer.
22
+ const file = await PDFNet.Filter.createMappedFileFromUString('../../TestFiles/tiger.pdf');
23
+ const file_sz = await file.mappedFileFileSize();
24
+
25
+ const file_reader = await PDFNet.FilterReader.create(file);
26
+
27
+ const mem = await file_reader.read(file_sz);
28
+ const doc = await PDFNet.PDFDoc.createFromBuffer(mem);
29
+
30
+ doc.initSecurityHandler();
31
+ const num_pages = await doc.getPageCount();
32
+
33
+ const writer = await PDFNet.ElementWriter.create();
34
+ const reader = await PDFNet.ElementReader.create();
35
+
36
+ // Create a duplicate of every page but copy only path objects
37
+ for (let i = 1; i <= num_pages; ++i) {
38
+ const itr = await doc.getPageIterator(2 * i - 1);
39
+
40
+ const cur_page = await itr.current();
41
+ reader.beginOnPage(cur_page);
42
+ const new_page = await doc.pageCreate(await cur_page.getMediaBox());
43
+ itr.next();
44
+ doc.pageInsert(itr, new_page);
45
+
46
+ writer.beginOnPage(new_page);
47
+ var element;
48
+ while (element = await reader.next()) { // Read page contents
49
+ writer.writeElement(element);
50
+ }
51
+
52
+ await writer.end();
53
+ await reader.end();
54
+ }
55
+
56
+ doc.save(outputPath + 'doc_memory_edit.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
57
+
58
+ // Save the document to a memory buffer.
59
+ const docbuf = await doc.saveMemoryBuffer(PDFNet.SDFDoc.SaveOptions.e_remove_unused);
60
+
61
+ // Write the contents of the buffer to the disk
62
+ fs.appendFileSync(outputPath + 'doc_memory_edit.txt', docbuf);
63
+
64
+ let dataStr = ''
65
+ // Read some data from the file stored in memory
66
+ reader.beginOnPage(await doc.getPage(1));
67
+ while (element = await reader.next()) {
68
+ if (await element.getType() == PDFNet.Element.Type.e_path) dataStr += 'Path, ';
69
+ }
70
+ reader.end();
71
+ console.log(dataStr);
72
+
73
+ console.log('\nDone. Result saved in doc_memory_edit.pdf and doc_memory_edit.txt ...');
74
+ } catch (err) {
75
+ console.log(err);
76
+ }
77
+ }
78
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
79
+ console.log('Error: ' + JSON.stringify(error));
80
+ }).then(function(){ return PDFNet.shutdown(); });
81
+ };
82
+ exports.runPDFDocMemoryTest();
83
+ })(exports);
84
+ // eslint-disable-next-line spaced-comment
85
+ //# sourceURL=PDFDocMemoryTest.js
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node PDFDocMemoryTest.js
@@ -1,85 +1,85 @@
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 fs = require('fs');
7
- const { PDFNet } = require('@pdftron/pdfnet-node');
8
- const PDFTronLicense = require('../LicenseKey/LicenseKey');
9
-
10
- ((exports) => {
11
- 'use strict';
12
-
13
- exports.runPDFDocMemoryTest = () => {
14
- const main = async () => {
15
- const outputPath = '../TestFiles/Output/';
16
-
17
- // The following sample illustrates how to read/write a PDF document from/to
18
- // a memory buffer. This is useful for applications that work with dynamic PDF
19
- // documents that don't need to be saved/read from a disk.
20
- try {
21
- // Read a PDF document in a memory buffer.
22
- const file = await PDFNet.Filter.createMappedFileFromUString('../TestFiles/tiger.pdf');
23
- const file_sz = await file.mappedFileFileSize();
24
-
25
- const file_reader = await PDFNet.FilterReader.create(file);
26
-
27
- const mem = await file_reader.read(file_sz);
28
- const doc = await PDFNet.PDFDoc.createFromBuffer(mem);
29
-
30
- doc.initSecurityHandler();
31
- const num_pages = await doc.getPageCount();
32
-
33
- const writer = await PDFNet.ElementWriter.create();
34
- const reader = await PDFNet.ElementReader.create();
35
-
36
- // Create a duplicate of every page but copy only path objects
37
- for (let i = 1; i <= num_pages; ++i) {
38
- const itr = await doc.getPageIterator(2 * i - 1);
39
-
40
- const cur_page = await itr.current();
41
- reader.beginOnPage(cur_page);
42
- const new_page = await doc.pageCreate(await cur_page.getMediaBox());
43
- itr.next();
44
- doc.pageInsert(itr, new_page);
45
-
46
- writer.beginOnPage(new_page);
47
- var element;
48
- while (element = await reader.next()) { // Read page contents
49
- writer.writeElement(element);
50
- }
51
-
52
- await writer.end();
53
- await reader.end();
54
- }
55
-
56
- doc.save(outputPath + 'doc_memory_edit.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
57
-
58
- // Save the document to a memory buffer.
59
- const docbuf = await doc.saveMemoryBuffer(PDFNet.SDFDoc.SaveOptions.e_remove_unused);
60
-
61
- // Write the contents of the buffer to the disk
62
- fs.appendFileSync(outputPath + 'doc_memory_edit.txt', docbuf);
63
-
64
- let dataStr = ''
65
- // Read some data from the file stored in memory
66
- reader.beginOnPage(await doc.getPage(1));
67
- while (element = await reader.next()) {
68
- if (await element.getType() == PDFNet.Element.Type.e_path) dataStr += 'Path, ';
69
- }
70
- reader.end();
71
- console.log(dataStr);
72
-
73
- console.log('\nDone. Result saved in doc_memory_edit.pdf and doc_memory_edit.txt ...');
74
- } catch (err) {
75
- console.log(err);
76
- }
77
- }
78
- PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
79
- console.log('Error: ' + JSON.stringify(error));
80
- }).then(function(){ return PDFNet.shutdown(); });
81
- };
82
- exports.runPDFDocMemoryTest();
83
- })(exports);
84
- // 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
+ const fs = require('fs');
7
+ const { PDFNet } = require('@pdftron/pdfnet-node');
8
+ const PDFTronLicense = require('../LicenseKey/LicenseKey');
9
+
10
+ ((exports) => {
11
+ 'use strict';
12
+
13
+ exports.runPDFDocMemoryTest = () => {
14
+ const main = async () => {
15
+ const outputPath = '../TestFiles/Output/';
16
+
17
+ // The following sample illustrates how to read/write a PDF document from/to
18
+ // a memory buffer. This is useful for applications that work with dynamic PDF
19
+ // documents that don't need to be saved/read from a disk.
20
+ try {
21
+ // Read a PDF document in a memory buffer.
22
+ const file = await PDFNet.Filter.createMappedFileFromUString('../TestFiles/tiger.pdf');
23
+ const file_sz = await file.mappedFileFileSize();
24
+
25
+ const file_reader = await PDFNet.FilterReader.create(file);
26
+
27
+ const mem = await file_reader.read(file_sz);
28
+ const doc = await PDFNet.PDFDoc.createFromBuffer(mem);
29
+
30
+ doc.initSecurityHandler();
31
+ const num_pages = await doc.getPageCount();
32
+
33
+ const writer = await PDFNet.ElementWriter.create();
34
+ const reader = await PDFNet.ElementReader.create();
35
+
36
+ // Create a duplicate of every page but copy only path objects
37
+ for (let i = 1; i <= num_pages; ++i) {
38
+ const itr = await doc.getPageIterator(2 * i - 1);
39
+
40
+ const cur_page = await itr.current();
41
+ reader.beginOnPage(cur_page);
42
+ const new_page = await doc.pageCreate(await cur_page.getMediaBox());
43
+ itr.next();
44
+ doc.pageInsert(itr, new_page);
45
+
46
+ writer.beginOnPage(new_page);
47
+ var element;
48
+ while (element = await reader.next()) { // Read page contents
49
+ writer.writeElement(element);
50
+ }
51
+
52
+ await writer.end();
53
+ await reader.end();
54
+ }
55
+
56
+ doc.save(outputPath + 'doc_memory_edit.pdf', PDFNet.SDFDoc.SaveOptions.e_remove_unused);
57
+
58
+ // Save the document to a memory buffer.
59
+ const docbuf = await doc.saveMemoryBuffer(PDFNet.SDFDoc.SaveOptions.e_remove_unused);
60
+
61
+ // Write the contents of the buffer to the disk
62
+ fs.appendFileSync(outputPath + 'doc_memory_edit.txt', docbuf);
63
+
64
+ let dataStr = ''
65
+ // Read some data from the file stored in memory
66
+ reader.beginOnPage(await doc.getPage(1));
67
+ while (element = await reader.next()) {
68
+ if (await element.getType() == PDFNet.Element.Type.e_path) dataStr += 'Path, ';
69
+ }
70
+ reader.end();
71
+ console.log(dataStr);
72
+
73
+ console.log('\nDone. Result saved in doc_memory_edit.pdf and doc_memory_edit.txt ...');
74
+ } catch (err) {
75
+ console.log(err);
76
+ }
77
+ }
78
+ PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
79
+ console.log('Error: ' + JSON.stringify(error));
80
+ }).then(function(){ return PDFNet.shutdown(); });
81
+ };
82
+ exports.runPDFDocMemoryTest();
83
+ })(exports);
84
+ // eslint-disable-next-line spaced-comment
85
85
  //# sourceURL=PDFDocMemoryTest.js