@pdftron/pdfnet-node-samples 9.2.0-1 → 9.2.0-2

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 (122) hide show
  1. package/package.json +1 -1
  2. package/samples/AddImageTest/AddImageTest.js +115 -115
  3. package/samples/AdvancedImagingTest/AdvancedImagingTest.js +64 -64
  4. package/samples/AnnotationTest/AnnotationTest.js +641 -641
  5. package/samples/BookmarkTest/BookmarkTest.js +219 -219
  6. package/samples/ContentReplacerTest/ContentReplacerTest.js +75 -75
  7. package/samples/ElementBuilderTest/ElementBuilderTest.js +513 -513
  8. package/samples/ElementEditTest/ElementEditTest.js +110 -110
  9. package/samples/ElementReaderAdvTest/ElementReaderAdvTest.js +305 -305
  10. package/samples/ElementReaderTest/ElementReaderTest.js +77 -77
  11. package/samples/EncTest/EncTest.js +175 -175
  12. package/samples/HTML2PDFTest/HTML2PDFTest.js +52 -42
  13. package/samples/LicenseKey/LicenseKey.js +11 -11
  14. package/samples/LogicalStructureTest/LogicalStructureTest.js +250 -250
  15. package/samples/OfficeTemplateTest/OfficeTemplateTest.js +76 -0
  16. package/samples/PDF2HtmlTest/PDF2HtmlTest.js +123 -123
  17. package/samples/PDF2OfficeTest/PDF2OfficeTest.js +158 -158
  18. package/samples/PDFATest/PDFATest.js +85 -85
  19. package/samples/PDFDrawTest/PDFDrawTest.js +305 -305
  20. package/samples/PDFLayersTest/PDFLayersTest.js +294 -294
  21. package/samples/PDFPageTest/PDFPageTest.js +189 -189
  22. package/samples/PDFRedactTest/PDFRedactTest.js +74 -74
  23. package/samples/RectTest/RectTest.js +40 -40
  24. package/samples/SDFTest/SDFTest.js +88 -88
  25. package/samples/StamperTest/StamperTest.js +255 -255
  26. package/samples/TestFiles/Misc-Fixed.pfa +1166 -1166
  27. package/samples/TestFiles/SHA-2 Root USERTrust RSA CA Sectigo timestamping.crt +34 -34
  28. package/samples/TestFiles/form1_annots.xfdf +33 -33
  29. package/samples/TestFiles/form1_data.xfdf +139 -139
  30. package/samples/TestFiles/my_stream.txt +2310 -2310
  31. package/samples/TextExtractTest/TextExtractTest.js +286 -286
  32. package/samples/TextSearchTest/TextSearchTest.js +121 -121
  33. package/samples/UndoRedoTest/UndoRedoTest.js +101 -101
  34. package/samples/UnicodeWriteTest/UnicodeWriteTest.js +173 -173
  35. package/samples/runall.bat +3 -4
  36. package/samples/runall.sh +4 -3
  37. package/samples/AddImageTest/RunTest.bat +0 -2
  38. package/samples/AddImageTest/RunTest.sh +0 -2
  39. package/samples/AdvancedImagingTest/RunTest.bat +0 -2
  40. package/samples/AdvancedImagingTest/RunTest.sh +0 -2
  41. package/samples/AnnotationTest/RunTest.bat +0 -2
  42. package/samples/AnnotationTest/RunTest.sh +0 -2
  43. package/samples/BookmarkTest/RunTest.bat +0 -2
  44. package/samples/BookmarkTest/RunTest.sh +0 -2
  45. package/samples/CAD2PDFTest/RunTest.bat +0 -2
  46. package/samples/CAD2PDFTest/RunTest.sh +0 -2
  47. package/samples/ContentReplacerTest/RunTest.bat +0 -2
  48. package/samples/ContentReplacerTest/RunTest.sh +0 -2
  49. package/samples/ConvertTest/RunTest.bat +0 -2
  50. package/samples/ConvertTest/RunTest.sh +0 -2
  51. package/samples/DigitalSignaturesTest/RunTest.bat +0 -2
  52. package/samples/DigitalSignaturesTest/RunTest.sh +0 -2
  53. package/samples/ElementBuilderTest/RunTest.bat +0 -2
  54. package/samples/ElementBuilderTest/RunTest.sh +0 -2
  55. package/samples/ElementEditTest/RunTest.bat +0 -2
  56. package/samples/ElementEditTest/RunTest.sh +0 -2
  57. package/samples/ElementReaderAdvTest/RunTest.bat +0 -2
  58. package/samples/ElementReaderAdvTest/RunTest.sh +0 -2
  59. package/samples/ElementReaderTest/RunTest.bat +0 -2
  60. package/samples/ElementReaderTest/RunTest.sh +0 -2
  61. package/samples/EncTest/RunTest.bat +0 -2
  62. package/samples/EncTest/RunTest.sh +0 -2
  63. package/samples/FDFTest/RunTest.bat +0 -2
  64. package/samples/FDFTest/RunTest.sh +0 -2
  65. package/samples/HTML2PDFTest/RunTest.bat +0 -2
  66. package/samples/HTML2PDFTest/RunTest.sh +0 -2
  67. package/samples/ImageExtractTest/RunTest.bat +0 -2
  68. package/samples/ImageExtractTest/RunTest.sh +0 -2
  69. package/samples/ImpositionTest/RunTest.bat +0 -2
  70. package/samples/ImpositionTest/RunTest.sh +0 -2
  71. package/samples/InteractiveFormsTest/RunTest.bat +0 -2
  72. package/samples/InteractiveFormsTest/RunTest.sh +0 -2
  73. package/samples/JBIG2Test/RunTest.bat +0 -2
  74. package/samples/JBIG2Test/RunTest.sh +0 -2
  75. package/samples/LogicalStructureTest/RunTest.bat +0 -2
  76. package/samples/LogicalStructureTest/RunTest.sh +0 -2
  77. package/samples/OCRTest/RunTest.bat +0 -2
  78. package/samples/OCRTest/RunTest.sh +0 -2
  79. package/samples/OfficeToPDFTest/RunTest.bat +0 -2
  80. package/samples/OfficeToPDFTest/RunTest.sh +0 -2
  81. package/samples/OptimizerTest/RunTest.bat +0 -2
  82. package/samples/OptimizerTest/RunTest.sh +0 -2
  83. package/samples/PDF2HtmlTest/RunTest.bat +0 -2
  84. package/samples/PDF2HtmlTest/RunTest.sh +0 -2
  85. package/samples/PDF2OfficeTest/RunTest.bat +0 -2
  86. package/samples/PDF2OfficeTest/RunTest.sh +0 -2
  87. package/samples/PDFATest/RunTest.bat +0 -2
  88. package/samples/PDFATest/RunTest.sh +0 -2
  89. package/samples/PDFDocMemoryTest/RunTest.bat +0 -2
  90. package/samples/PDFDocMemoryTest/RunTest.sh +0 -2
  91. package/samples/PDFDrawTest/RunTest.bat +0 -2
  92. package/samples/PDFDrawTest/RunTest.sh +0 -2
  93. package/samples/PDFLayersTest/RunTest.bat +0 -2
  94. package/samples/PDFLayersTest/RunTest.sh +0 -2
  95. package/samples/PDFPackageTest/RunTest.bat +0 -2
  96. package/samples/PDFPackageTest/RunTest.sh +0 -2
  97. package/samples/PDFPageTest/RunTest.bat +0 -2
  98. package/samples/PDFPageTest/RunTest.sh +0 -2
  99. package/samples/PDFRedactTest/RunTest.bat +0 -2
  100. package/samples/PDFRedactTest/RunTest.sh +0 -2
  101. package/samples/PageLabelsTest/RunTest.bat +0 -2
  102. package/samples/PageLabelsTest/RunTest.sh +0 -2
  103. package/samples/PatternTest/RunTest.bat +0 -2
  104. package/samples/PatternTest/RunTest.sh +0 -2
  105. package/samples/RectTest/RunTest.bat +0 -2
  106. package/samples/RectTest/RunTest.sh +0 -2
  107. package/samples/SDFTest/RunTest.bat +0 -2
  108. package/samples/SDFTest/RunTest.sh +0 -2
  109. package/samples/StamperTest/RunTest.bat +0 -2
  110. package/samples/StamperTest/RunTest.sh +0 -2
  111. package/samples/TextExtractTest/RunTest.bat +0 -2
  112. package/samples/TextExtractTest/RunTest.sh +0 -2
  113. package/samples/TextSearchTest/RunTest.bat +0 -2
  114. package/samples/TextSearchTest/RunTest.sh +0 -2
  115. package/samples/U3DTest/RunTest.bat +0 -2
  116. package/samples/U3DTest/RunTest.sh +0 -2
  117. package/samples/UndoRedoTest/RunTest.bat +0 -2
  118. package/samples/UndoRedoTest/RunTest.sh +0 -2
  119. package/samples/UnicodeWriteTest/RunTest.bat +0 -2
  120. package/samples/UnicodeWriteTest/RunTest.sh +0 -2
  121. package/samples/WebViewerConvertTest/RunTest.bat +0 -2
  122. package/samples/WebViewerConvertTest/RunTest.sh +0 -2
@@ -29,17 +29,28 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
29
29
  exports.runHTML2PDFTest = () => {
30
30
  const main = async () => {
31
31
  const outputPath = '../TestFiles/Output/html2pdf_example';
32
- const host = 'http://www.gutenberg.org/';
33
- const page0 = 'wiki/Main_Page';
34
- const page1 = 'catalog/';
35
- const page2 = 'browse/recent/last1';
36
- const page3 = 'wiki/Gutenberg:The_Sheet_Music_Project';
37
-
38
- // For HTML2PDF we need to locate the html2pdf module. If placed with the
39
- // PDFNet library, or in the current working directory, it will be loaded
40
- // automatically. Otherwise, it must be set manually using HTML2PDF.setModulePath.
32
+ const host = 'https://www.pdftron.com';
33
+ const page0 = '/';
34
+ const page1 = '/support';
35
+ const page2 = '/blog';
36
+ // For HTML2PDF we need to locate the html2pdf module. If placed with the
37
+ // PDFNet library, or in the current working directory, it will be loaded
38
+ // automatically. Otherwise, it must be set manually using HTML2PDF.setModulePath.
41
39
  await PDFNet.HTML2PDF.setModulePath('../../lib/');
42
40
 
41
+ try {
42
+ if(await !PDFNet.HTML2PDF.isModuleAvailable()){
43
+ console.log('Unable to run HTML2PDFTest: PDFTron SDK HTML2PDF module not available.');
44
+ console.log('---------------------------------------------------------------');
45
+ console.log('The HTML2PDF module is an optional add-on, available for download');
46
+ console.log('at https://www.pdftron.com/. If you have already downloaded this');
47
+ console.log('module, ensure that the SDK is able to find the required files');
48
+ console.log('using the HTML2PDF.setModulePath() function.');
49
+ }
50
+ } catch (err) {
51
+ console.log(err);
52
+ }
53
+
43
54
  //--------------------------------------------------------------------------------
44
55
  // Example 1) Simple conversion of a web page to a PDF doc.
45
56
 
@@ -69,16 +80,16 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
69
80
 
70
81
  // create the HTML2PDF converter object and modify the output of the PDF pages
71
82
  const html2pdf = await PDFNet.HTML2PDF.create();
72
- html2pdf.setImageQuality(25);
73
83
  html2pdf.setPaperSize(PDFNet.PrinterMode.PaperSize.e_11x17);
74
84
 
75
85
  // insert the web page to convert
76
86
  html2pdf.insertFromUrl(host.concat(page0));
87
+
77
88
  // convert the web page, appending generated PDF pages to doc
78
89
  if (await html2pdf.convert(doc)) {
79
90
  doc.save(outputPath.concat('_02.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
80
91
  } else {
81
- console.log('conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
92
+ console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
82
93
  console.log(await html2pdf.getLog());
83
94
  }
84
95
  } catch (err) {
@@ -86,41 +97,40 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
86
97
  }
87
98
 
88
99
  //--------------------------------------------------------------------------------
89
- // Example 3) Convert multiple web pages, adding a table of contents, and setting
90
- // the first page as a cover page, not to be included with the table of contents outline.
100
+ // Example 3) Convert multiple web pages
91
101
 
92
102
  try {
93
- // Add a cover page, which is excluded from the outline, and ignore any errors
94
- const cover = await PDFNet.HTML2PDF.WebPageSettings.create();
95
- cover.setLoadErrorHandling(PDFNet.HTML2PDF.WebPageSettings.ErrorHandling.e_ignore);
96
- await cover.setIncludeInOutline(false);
97
-
98
- const html2pdf = await PDFNet.HTML2PDF.create();
99
- html2pdf.insertFromUrl2(host.concat(page3), cover);
100
-
101
- // Add a table of contents settings (modifying the settings is optional)
102
- const toc = await PDFNet.HTML2PDF.TOCSettings.create();
103
- await toc.setDottedLines(false);
104
- html2pdf.insertTOC2(toc);
105
-
106
- // Now add the rest of the web pages, disabling external links and
107
- // skipping any web pages that fail to load.
108
- //
109
- // Note that the order of insertion matters, so these will appear
110
- // after the cover and table of contents, in the order below.
111
- const settings = await PDFNet.HTML2PDF.WebPageSettings.create();
112
- settings.setLoadErrorHandling(PDFNet.HTML2PDF.WebPageSettings.ErrorHandling.e_skip);
113
- await settings.setExternalLinks(false);
103
+ // convert page 0 into pdf
104
+ const doc = await PDFNet.PDFDoc.create();
114
105
 
115
- html2pdf.insertFromUrl2(host.concat(page0), settings);
116
- html2pdf.insertFromUrl2(host.concat(page1), settings);
117
- html2pdf.insertFromUrl2(host.concat(page2), settings);
106
+ const converter = await PDFNet.HTML2PDF.create();
118
107
 
119
- const doc = await PDFNet.PDFDoc.create();
120
- if (await html2pdf.convert(doc)) {
108
+ const header = '<div style=\'width:15%;margin-left:0.5cm;text-align:left;font-size:10px;color:#0000FF\'><span class=\'date\'></span></div><div style=\'width:70%;direction:rtl;white-space:nowrap;overflow:hidden;text-overflow:clip;text-align:center;font-size:10px;color:#0000FF\'><span>PDFTRON HEADER EXAMPLE</span></div><div style=\'width:15%;margin-right:0.5cm;text-align:right;font-size:10px;color:#0000FF\'><span class=\'pageNumber\'></span> of <span class=\'totalPages\'></span></div>';
109
+ const footer = '<div style=\'width:15%;margin-left:0.5cm;text-align:left;font-size:7px;color:#FF00FF\'><span class=\'date\'></span></div><div style=\'width:70%;direction:rtl;white-space:nowrap;overflow:hidden;text-overflow:clip;text-align:center;font-size:7px;color:#FF00FF\'><span>PDFTRON FOOTER EXAMPLE</span></div><div style=\'width:15%;margin-right:0.5cm;text-align:right;font-size:7px;color:#FF00FF\'><span class=\'pageNumber\'></span> of <span class=\'totalPages\'></span></div>';
110
+ converter.setHeader(header);
111
+ converter.setFooter(footer);
112
+ converter.setMargins('1cm', '2cm', '.5cm', '1.5cm');
113
+ const settings = await PDFNet.HTML2PDF.WebPageSettings.create();
114
+ await settings.setZoom(0.5);
115
+ converter.insertFromUrl2(host.concat(page0), settings);
116
+ const is_conversion_0_successful = await converter.convert(doc);
117
+
118
+ // convert page 1 with the same settings, appending generated PDF pages to doc
119
+ converter.insertFromUrl2(host.concat(page1), settings);
120
+ const is_conversion_1_successful = await converter.convert(doc);
121
+
122
+ // convert page 2 with different settings, appending generated PDF pages to doc
123
+ const another_converter = await PDFNet.HTML2PDF.create();
124
+ another_converter.setLandscape(true);
125
+ const another_settings = await PDFNet.HTML2PDF.WebPageSettings.create();
126
+ another_settings.setPrintBackground(false);
127
+ another_converter.insertFromUrl2(host.concat(page2), another_settings);
128
+ const is_conversion_2_successful = await another_converter.convert(doc);
129
+
130
+ if(is_conversion_0_successful && is_conversion_1_successful && is_conversion_2_successful) {
121
131
  doc.save(outputPath.concat('_03.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
122
132
  } else {
123
- console.log('conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
133
+ console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
124
134
  console.log(await html2pdf.getLog());
125
135
  }
126
136
  } catch (err) {
@@ -133,13 +143,13 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
133
143
  try {
134
144
  const html2pdf = await PDFNet.HTML2PDF.create();
135
145
  const doc = await PDFNet.PDFDoc.create();
136
- const html = '<html><body><h1>Heading</h1><p>Paragraph.</p></body></html>'
146
+ const html = '<html><body><h1>Heading</h1><p>Paragraph.</p></body></html>';
137
147
 
138
148
  html2pdf.insertFromHtmlString(html);
139
149
  if (await html2pdf.convert(doc)) {
140
150
  doc.save(outputPath.concat('_04.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
141
151
  } else {
142
- console.log('conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
152
+ console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
143
153
  console.log(await html2pdf.getLog());
144
154
  }
145
155
  } catch (err) {
@@ -1,11 +1,11 @@
1
- //---------------------------------------------------------------------------------------
2
- // Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3
- // Consult legal.txt regarding legal and license information.
4
- //---------------------------------------------------------------------------------------
5
-
6
- //"Enter your key here. If you don't have it, please go to https://www.pdftron.com/pws/get-key to obtain a demo license or https://www.pdftron.com/form/contact-sales to obtain a production key.
7
- const LicenseKey = 'YOUR_PDFTRON_LICENSE_KEY';
8
- if(LicenseKey == 'YOUR_PDFTRON_LICENSE_KEY'){
9
- throw ('Please enter your license key by replacing \'YOUR_PDFTRON_LICENSE_KEY\' that is assigned to the LicenseKey variable in Samples/LicenseKey/LicenseKey.js. If you do not have a license key, please go to https://www.pdftron.com/pws/get-key to obtain a demo license or https://www.pdftron.com/form/contact-sales to obtain a production key.');
10
- }
11
- exports.Key = LicenseKey;
1
+ //---------------------------------------------------------------------------------------
2
+ // Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
3
+ // Consult legal.txt regarding legal and license information.
4
+ //---------------------------------------------------------------------------------------
5
+
6
+ //"Enter your key here. If you don't have it, please go to https://www.pdftron.com/pws/get-key to obtain a demo license or https://www.pdftron.com/form/contact-sales to obtain a production key.
7
+ const LicenseKey = 'YOUR_PDFTRON_LICENSE_KEY';
8
+ if(LicenseKey == 'YOUR_PDFTRON_LICENSE_KEY'){
9
+ throw ('Please enter your license key by replacing \'YOUR_PDFTRON_LICENSE_KEY\' that is assigned to the LicenseKey variable in Samples/LicenseKey/LicenseKey.js. If you do not have a license key, please go to https://www.pdftron.com/pws/get-key to obtain a demo license or https://www.pdftron.com/form/contact-sales to obtain a production key.');
10
+ }
11
+ exports.Key = LicenseKey;