@pdftron/pdfnet-node-samples 10.9.0 → 10.10.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.
- package/{samples/AddImageTest → AddImageTest}/AddImageTest.js +115 -115
- package/{samples/AdvancedImagingTest → AdvancedImagingTest}/AdvancedImagingTest.js +78 -78
- package/{samples/AnnotationTest → AnnotationTest}/AnnotationTest.js +641 -641
- package/{samples/BookmarkTest → BookmarkTest}/BookmarkTest.js +219 -219
- package/{samples/CAD2PDFTest → CAD2PDFTest}/CAD2PDFTest.js +79 -79
- package/{samples/ContentReplacerTest → ContentReplacerTest}/ContentReplacerTest.js +75 -75
- package/{samples/ConvertPrintTest → ConvertPrintTest}/ConvertPrintTest.js +153 -153
- package/{samples/ConvertTest → ConvertTest}/ConvertTest.js +203 -203
- package/{samples/DataExtractionTest → DataExtractionTest}/DataExtractionTest.js +214 -214
- package/{samples/DigitalSignaturesTest → DigitalSignaturesTest}/DigitalSignaturesTest.js +622 -527
- package/{samples/DocumentCreationTest → DocumentCreationTest}/DocumentCreationTest.js +409 -409
- package/{samples/ElementBuilderTest → ElementBuilderTest}/ElementBuilderTest.js +513 -513
- package/{samples/ElementEditTest → ElementEditTest}/ElementEditTest.js +110 -110
- package/{samples/ElementReaderAdvTest → ElementReaderAdvTest}/ElementReaderAdvTest.js +305 -305
- package/{samples/ElementReaderTest → ElementReaderTest}/ElementReaderTest.js +77 -77
- package/{samples/EncTest → EncTest}/EncTest.js +175 -175
- package/{samples/FDFTest → FDFTest}/FDFTest.js +218 -218
- package/{samples/HTML2PDFTest → HTML2PDFTest}/HTML2PDFTest.js +164 -164
- package/{samples/HighlightsTest → HighlightsTest}/HighlightsTest.js +97 -97
- package/{samples/ImageExtractTest → ImageExtractTest}/ImageExtractTest.js +129 -129
- package/{samples/ImpositionTest → ImpositionTest}/ImpositionTest.js +86 -86
- package/{samples/InteractiveFormsTest → InteractiveFormsTest}/InteractiveFormsTest.js +381 -381
- package/{samples/JBIG2Test → JBIG2Test}/JBIG2Test.js +88 -88
- package/{samples/LicenseKey → LicenseKey}/LicenseKey.js +11 -11
- package/{samples/LogicalStructureTest → LogicalStructureTest}/LogicalStructureTest.js +250 -250
- package/{samples/OCRTest → OCRTest}/OCRTest.js +235 -235
- package/{samples/OfficeTemplateTest → OfficeTemplateTest}/OfficeTemplateTest.js +79 -79
- package/{samples/OfficeToPDFTest → OfficeToPDFTest}/OfficeToPDFTest.js +125 -125
- package/{samples/OptimizerTest → OptimizerTest}/OptimizerTest.js +191 -191
- package/{samples/PDF2HtmlTest → PDF2HtmlTest}/PDF2HtmlTest.js +123 -123
- package/{samples/PDF2OfficeTest → PDF2OfficeTest}/PDF2OfficeTest.js +158 -158
- package/{samples/PDFATest → PDFATest}/PDFATest.js +85 -85
- package/{samples/PDFDocMemoryTest → PDFDocMemoryTest}/PDFDocMemoryTest.js +84 -84
- package/{samples/PDFDrawTest → PDFDrawTest}/PDFDrawTest.js +305 -305
- package/{samples/PDFLayersTest → PDFLayersTest}/PDFLayersTest.js +294 -294
- package/{samples/PDFPackageTest → PDFPackageTest}/PDFPackageTest.js +111 -111
- package/{samples/PDFPageTest → PDFPageTest}/PDFPageTest.js +189 -189
- package/{samples/PDFRedactTest → PDFRedactTest}/PDFRedactTest.js +74 -74
- package/{samples/PageLabelsTest → PageLabelsTest}/PageLabelsTest.js +138 -138
- package/{samples/PatternTest → PatternTest}/PatternTest.js +226 -226
- package/{samples/RectTest → RectTest}/RectTest.js +40 -40
- package/{samples/SDFTest → SDFTest}/SDFTest.js +87 -87
- package/{samples/StamperTest → StamperTest}/StamperTest.js +255 -255
- package/{samples/TestFiles → TestFiles}/Misc-Fixed.pfa +1166 -1166
- package/{samples/TestFiles → TestFiles}/SHA-2 Root USERTrust RSA CA Sectigo timestamping.crt +34 -34
- package/{samples/TestFiles → TestFiles}/form1_annots.xfdf +33 -33
- package/{samples/TestFiles → TestFiles}/form1_data.xfdf +139 -139
- package/{samples/TestFiles → TestFiles}/my_stream.txt +2310 -2310
- package/{samples/TestFiles → TestFiles}/tiger.svg +378 -378
- package/{samples/TextExtractTest → TextExtractTest}/TextExtractTest.js +286 -286
- package/{samples/TextSearchTest → TextSearchTest}/TextSearchTest.js +121 -121
- package/{samples/U3DTest → U3DTest}/U3DTest.js +104 -104
- package/{samples/UndoRedoTest → UndoRedoTest}/UndoRedoTest.js +101 -101
- package/{samples/UnicodeWriteTest → UnicodeWriteTest}/UnicodeWriteTest.js +173 -173
- package/{samples/WebViewerConvertTest → WebViewerConvertTest}/WebViewerConvertTest.js +135 -135
- package/legal.txt +632 -0
- package/license.pdf +0 -0
- package/package.json +20 -21
- package/readme.md +38 -13
- package/{samples/runall.bat → runall.bat} +12 -12
- package/{samples/runall.sh → runall.sh} +15 -15
- /package/{samples/TestFiles → TestFiles}/BusinessCardTemplate.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/Fishermen.docx +0 -0
- /package/{samples/TestFiles → TestFiles}/Font_licenses.txt +0 -0
- /package/{samples/TestFiles → TestFiles}/GlobalSignRootForTST.cer +0 -0
- /package/{samples/TestFiles → TestFiles}/License.txt +0 -0
- /package/{samples/TestFiles → TestFiles}/NotoSans_with_hindi.ttf +0 -0
- /package/{samples/TestFiles → TestFiles}/Output/empty +0 -0
- /package/{samples/TestFiles → TestFiles}/SYH_Letter.docx +0 -0
- /package/{samples/TestFiles → TestFiles}/TigerText.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/US061222892-a.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/butterfly.png +0 -0
- /package/{samples/TestFiles → TestFiles}/credit card numbers.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/dice.jpg +0 -0
- /package/{samples/TestFiles → TestFiles}/dice.u3d +0 -0
- /package/{samples/TestFiles → TestFiles}/doc_to_sign.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/factsheet_Arabic.docx +0 -0
- /package/{samples/TestFiles → TestFiles}/financial.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/fish.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/font.ttf +0 -0
- /package/{samples/TestFiles → TestFiles}/form1.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/form1_data.fdf +0 -0
- /package/{samples/TestFiles → TestFiles}/formfields-scanned-withfields.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/formfields-scanned.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/formfields.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/grayscale.tif +0 -0
- /package/{samples/TestFiles → TestFiles}/hindi_sample_utf16le.txt +0 -0
- /package/{samples/TestFiles → TestFiles}/imagemask.dat +0 -0
- /package/{samples/TestFiles → TestFiles}/logo_red.png +0 -0
- /package/{samples/TestFiles → TestFiles}/lorem_ipsum.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/multipage.tif +0 -0
- /package/{samples/TestFiles → TestFiles}/newsletter.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/newsletter.xod +0 -0
- /package/{samples/TestFiles → TestFiles}/numbered.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/op_blend_test.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/palm.jp2 +0 -0
- /package/{samples/TestFiles → TestFiles}/paragraphs_and_tables.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/pdfnet.gif +0 -0
- /package/{samples/TestFiles → TestFiles}/pdftron.bmp +0 -0
- /package/{samples/TestFiles → TestFiles}/pdftron.cer +0 -0
- /package/{samples/TestFiles → TestFiles}/pdftron.pfx +0 -0
- /package/{samples/TestFiles → TestFiles}/pdftron_smart_substitution.plugin +0 -0
- /package/{samples/TestFiles → TestFiles}/peppers.jpg +0 -0
- /package/{samples/TestFiles → TestFiles}/signature.jpg +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-emf.emf +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-excel_2007.xlsx +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-outlook.msg +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-powerpoint_2007.pptx +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-publisher.pub +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-rtf.rtf +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-text.txt +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-visio.vsd +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage.html +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage.mht +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/colorschememapping.xml +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/filelist.xml +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image001.gif +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image002.png +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image003.jpg +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image004.emz +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image005.gif +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image006.png +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/image007.gif +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/oledata.mso +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-webpage_files/themedata.thmx +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-word_2007.docx +0 -0
- /package/{samples/TestFiles → TestFiles}/simple-xps.xps +0 -0
- /package/{samples/TestFiles → TestFiles}/table.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/tagged.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/the_rime_of_the_ancient_mariner.docx +0 -0
- /package/{samples/TestFiles → TestFiles}/tiger.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/waiver.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/waiver_withApprovalField.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/waiver_withApprovalField_certified.pdf +0 -0
- /package/{samples/TestFiles → TestFiles}/waiver_withApprovalField_certified_approved.pdf +0 -0
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
|
|
3
|
-
// Consult legal.txt regarding legal and license information.
|
|
4
|
-
//---------------------------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
//---------------------------------------------------------------------------------------
|
|
7
|
-
// The following sample illustrates how to convert HTML pages to PDF format using
|
|
8
|
-
// the HTML2PDF class.
|
|
9
|
-
//
|
|
10
|
-
// 'pdftron.PDF.HTML2PDF' is an optional PDFNet Add-On utility class that can be
|
|
11
|
-
// used to convert HTML web pages into PDF documents by using an external module (html2pdf).
|
|
12
|
-
//
|
|
13
|
-
// html2pdf modules can be downloaded from http://www.pdftron.com/pdfnet/downloads.html.
|
|
14
|
-
//
|
|
15
|
-
// Users can convert HTML pages to PDF using the following operations:
|
|
16
|
-
// - Simple one line static method to convert a single web page to PDF.
|
|
17
|
-
// - Convert HTML pages from URL or string, plus optional table of contents, in user defined order.
|
|
18
|
-
// - Optionally configure settings for proxy, images, java script, and more for each HTML page.
|
|
19
|
-
// - Optionally configure the PDF output, including page size, margins, orientation, and more.
|
|
20
|
-
// - Optionally add table of contents, including setting the depth and appearance.
|
|
21
|
-
//---------------------------------------------------------------------------------------
|
|
22
|
-
|
|
23
|
-
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
24
|
-
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
25
|
-
|
|
26
|
-
((exports) => {
|
|
27
|
-
'use strict';
|
|
28
|
-
|
|
29
|
-
exports.runHTML2PDFTest = () => {
|
|
30
|
-
const main = async () => {
|
|
31
|
-
const outputPath = '../TestFiles/Output/html2pdf_example';
|
|
32
|
-
const host = 'https://docs.apryse.com';
|
|
33
|
-
const page0 = '/';
|
|
34
|
-
const page1 = '/all-products/';
|
|
35
|
-
const page2 = '/documentation/web/faq';
|
|
36
|
-
|
|
37
|
-
// For HTML2PDF we need to locate the html2pdf module. If placed with the
|
|
38
|
-
// PDFNet library, or in the current working directory, it will be loaded
|
|
39
|
-
// automatically. Otherwise, it must be set manually using HTML2PDF.setModulePath.
|
|
40
|
-
await PDFNet.HTML2PDF.setModulePath('../../lib/');
|
|
41
|
-
|
|
42
|
-
if(!(await PDFNet.HTML2PDF.isModuleAvailable())) {
|
|
43
|
-
console.log('Unable to run HTML2PDFTest: Apryse 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
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
//--------------------------------------------------------------------------------
|
|
54
|
-
// Example 1) Simple conversion of a web page to a PDF doc.
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
58
|
-
const doc = await PDFNet.PDFDoc.create();
|
|
59
|
-
|
|
60
|
-
html2pdf.insertFromUrl(host.concat(page0));
|
|
61
|
-
// now convert a web page, sending generated PDF pages to doc
|
|
62
|
-
await html2pdf.convert(doc);
|
|
63
|
-
doc.save(outputPath.concat('_01.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
64
|
-
} catch (err) {
|
|
65
|
-
console.log(err);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
//--------------------------------------------------------------------------------
|
|
69
|
-
// Example 2) Modify the settings of the generated PDF pages and attach to an
|
|
70
|
-
// existing PDF document.
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
// open the existing PDF, and initialize the security handler
|
|
74
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath('../TestFiles/numbered.pdf');
|
|
75
|
-
await doc.initSecurityHandler();
|
|
76
|
-
|
|
77
|
-
// create the HTML2PDF converter object and modify the output of the PDF pages
|
|
78
|
-
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
79
|
-
html2pdf.setPaperSize(PDFNet.PrinterMode.PaperSize.e_11x17);
|
|
80
|
-
|
|
81
|
-
// insert the web page to convert
|
|
82
|
-
html2pdf.insertFromUrl(host.concat(page0));
|
|
83
|
-
|
|
84
|
-
// convert the web page, appending generated PDF pages to doc
|
|
85
|
-
await html2pdf.convert(doc);
|
|
86
|
-
doc.save(outputPath.concat('_02.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
87
|
-
} catch (err) {
|
|
88
|
-
console.log(err);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
//--------------------------------------------------------------------------------
|
|
92
|
-
// Example 3) Convert multiple web pages
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
// convert page 0 into pdf
|
|
96
|
-
const doc = await PDFNet.PDFDoc.create();
|
|
97
|
-
|
|
98
|
-
const converter = await PDFNet.HTML2PDF.create();
|
|
99
|
-
|
|
100
|
-
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>';
|
|
101
|
-
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>';
|
|
102
|
-
converter.setHeader(header);
|
|
103
|
-
converter.setFooter(footer);
|
|
104
|
-
converter.setMargins('1cm', '2cm', '.5cm', '1.5cm');
|
|
105
|
-
const settings = await PDFNet.HTML2PDF.WebPageSettings.create();
|
|
106
|
-
await settings.setZoom(0.5);
|
|
107
|
-
converter.insertFromUrl2(host.concat(page0), settings);
|
|
108
|
-
await converter.convert(doc);
|
|
109
|
-
|
|
110
|
-
// convert page 1 with the same settings, appending generated PDF pages to doc
|
|
111
|
-
converter.insertFromUrl2(host.concat(page1), settings);
|
|
112
|
-
await converter.convert(doc);
|
|
113
|
-
|
|
114
|
-
// convert page 2 with different settings, appending generated PDF pages to doc
|
|
115
|
-
const another_converter = await PDFNet.HTML2PDF.create();
|
|
116
|
-
another_converter.setLandscape(true);
|
|
117
|
-
const another_settings = await PDFNet.HTML2PDF.WebPageSettings.create();
|
|
118
|
-
another_settings.setPrintBackground(false);
|
|
119
|
-
another_converter.insertFromUrl2(host.concat(page2), another_settings);
|
|
120
|
-
await another_converter.convert(doc);
|
|
121
|
-
|
|
122
|
-
doc.save(outputPath.concat('_03.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
123
|
-
} catch (err) {
|
|
124
|
-
console.log(err);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
//--------------------------------------------------------------------------------
|
|
128
|
-
// Example 4) Convert HTML string to PDF.
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
132
|
-
const doc = await PDFNet.PDFDoc.create();
|
|
133
|
-
const html = '<html><body><h1>Heading</h1><p>Paragraph.</p></body></html>';
|
|
134
|
-
|
|
135
|
-
html2pdf.insertFromHtmlString(html);
|
|
136
|
-
await html2pdf.convert(doc);
|
|
137
|
-
doc.save(outputPath.concat('_04.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
138
|
-
} catch (err) {
|
|
139
|
-
console.log(err);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
//--------------------------------------------------------------------------------
|
|
143
|
-
// Example 5) Set the location of the log file to be used during conversion.
|
|
144
|
-
|
|
145
|
-
try {
|
|
146
|
-
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
147
|
-
const doc = await PDFNet.PDFDoc.create();
|
|
148
|
-
html2pdf.setLogFilePath('../TestFiles/Output/html2pdf.log');
|
|
149
|
-
html2pdf.insertFromUrl(host.concat(page0));
|
|
150
|
-
await html2pdf.convert(doc);
|
|
151
|
-
doc.save(outputPath.concat('_05.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
152
|
-
} catch (err) {
|
|
153
|
-
console.log(err);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
console.log('Test Complete!');
|
|
157
|
-
}
|
|
158
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
|
|
159
|
-
console.log('Error: ' + JSON.stringify(error));
|
|
160
|
-
}).then(function(){ return PDFNet.shutdown(); });
|
|
161
|
-
};
|
|
162
|
-
exports.runHTML2PDFTest();
|
|
163
|
-
})(exports);
|
|
164
|
-
// eslint-disable-next-line spaced-comment
|
|
1
|
+
//---------------------------------------------------------------------------------------
|
|
2
|
+
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
|
|
3
|
+
// Consult legal.txt regarding legal and license information.
|
|
4
|
+
//---------------------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
//---------------------------------------------------------------------------------------
|
|
7
|
+
// The following sample illustrates how to convert HTML pages to PDF format using
|
|
8
|
+
// the HTML2PDF class.
|
|
9
|
+
//
|
|
10
|
+
// 'pdftron.PDF.HTML2PDF' is an optional PDFNet Add-On utility class that can be
|
|
11
|
+
// used to convert HTML web pages into PDF documents by using an external module (html2pdf).
|
|
12
|
+
//
|
|
13
|
+
// html2pdf modules can be downloaded from http://www.pdftron.com/pdfnet/downloads.html.
|
|
14
|
+
//
|
|
15
|
+
// Users can convert HTML pages to PDF using the following operations:
|
|
16
|
+
// - Simple one line static method to convert a single web page to PDF.
|
|
17
|
+
// - Convert HTML pages from URL or string, plus optional table of contents, in user defined order.
|
|
18
|
+
// - Optionally configure settings for proxy, images, java script, and more for each HTML page.
|
|
19
|
+
// - Optionally configure the PDF output, including page size, margins, orientation, and more.
|
|
20
|
+
// - Optionally add table of contents, including setting the depth and appearance.
|
|
21
|
+
//---------------------------------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
24
|
+
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
25
|
+
|
|
26
|
+
((exports) => {
|
|
27
|
+
'use strict';
|
|
28
|
+
|
|
29
|
+
exports.runHTML2PDFTest = () => {
|
|
30
|
+
const main = async () => {
|
|
31
|
+
const outputPath = '../TestFiles/Output/html2pdf_example';
|
|
32
|
+
const host = 'https://docs.apryse.com';
|
|
33
|
+
const page0 = '/';
|
|
34
|
+
const page1 = '/all-products/';
|
|
35
|
+
const page2 = '/documentation/web/faq';
|
|
36
|
+
|
|
37
|
+
// For HTML2PDF we need to locate the html2pdf module. If placed with the
|
|
38
|
+
// PDFNet library, or in the current working directory, it will be loaded
|
|
39
|
+
// automatically. Otherwise, it must be set manually using HTML2PDF.setModulePath.
|
|
40
|
+
await PDFNet.HTML2PDF.setModulePath('../../lib/');
|
|
41
|
+
|
|
42
|
+
if(!(await PDFNet.HTML2PDF.isModuleAvailable())) {
|
|
43
|
+
console.log('Unable to run HTML2PDFTest: Apryse 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
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//--------------------------------------------------------------------------------
|
|
54
|
+
// Example 1) Simple conversion of a web page to a PDF doc.
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
58
|
+
const doc = await PDFNet.PDFDoc.create();
|
|
59
|
+
|
|
60
|
+
html2pdf.insertFromUrl(host.concat(page0));
|
|
61
|
+
// now convert a web page, sending generated PDF pages to doc
|
|
62
|
+
await html2pdf.convert(doc);
|
|
63
|
+
doc.save(outputPath.concat('_01.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.log(err);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//--------------------------------------------------------------------------------
|
|
69
|
+
// Example 2) Modify the settings of the generated PDF pages and attach to an
|
|
70
|
+
// existing PDF document.
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
// open the existing PDF, and initialize the security handler
|
|
74
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath('../TestFiles/numbered.pdf');
|
|
75
|
+
await doc.initSecurityHandler();
|
|
76
|
+
|
|
77
|
+
// create the HTML2PDF converter object and modify the output of the PDF pages
|
|
78
|
+
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
79
|
+
html2pdf.setPaperSize(PDFNet.PrinterMode.PaperSize.e_11x17);
|
|
80
|
+
|
|
81
|
+
// insert the web page to convert
|
|
82
|
+
html2pdf.insertFromUrl(host.concat(page0));
|
|
83
|
+
|
|
84
|
+
// convert the web page, appending generated PDF pages to doc
|
|
85
|
+
await html2pdf.convert(doc);
|
|
86
|
+
doc.save(outputPath.concat('_02.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
console.log(err);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//--------------------------------------------------------------------------------
|
|
92
|
+
// Example 3) Convert multiple web pages
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
// convert page 0 into pdf
|
|
96
|
+
const doc = await PDFNet.PDFDoc.create();
|
|
97
|
+
|
|
98
|
+
const converter = await PDFNet.HTML2PDF.create();
|
|
99
|
+
|
|
100
|
+
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>';
|
|
101
|
+
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>';
|
|
102
|
+
converter.setHeader(header);
|
|
103
|
+
converter.setFooter(footer);
|
|
104
|
+
converter.setMargins('1cm', '2cm', '.5cm', '1.5cm');
|
|
105
|
+
const settings = await PDFNet.HTML2PDF.WebPageSettings.create();
|
|
106
|
+
await settings.setZoom(0.5);
|
|
107
|
+
converter.insertFromUrl2(host.concat(page0), settings);
|
|
108
|
+
await converter.convert(doc);
|
|
109
|
+
|
|
110
|
+
// convert page 1 with the same settings, appending generated PDF pages to doc
|
|
111
|
+
converter.insertFromUrl2(host.concat(page1), settings);
|
|
112
|
+
await converter.convert(doc);
|
|
113
|
+
|
|
114
|
+
// convert page 2 with different settings, appending generated PDF pages to doc
|
|
115
|
+
const another_converter = await PDFNet.HTML2PDF.create();
|
|
116
|
+
another_converter.setLandscape(true);
|
|
117
|
+
const another_settings = await PDFNet.HTML2PDF.WebPageSettings.create();
|
|
118
|
+
another_settings.setPrintBackground(false);
|
|
119
|
+
another_converter.insertFromUrl2(host.concat(page2), another_settings);
|
|
120
|
+
await another_converter.convert(doc);
|
|
121
|
+
|
|
122
|
+
doc.save(outputPath.concat('_03.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
123
|
+
} catch (err) {
|
|
124
|
+
console.log(err);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//--------------------------------------------------------------------------------
|
|
128
|
+
// Example 4) Convert HTML string to PDF.
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
132
|
+
const doc = await PDFNet.PDFDoc.create();
|
|
133
|
+
const html = '<html><body><h1>Heading</h1><p>Paragraph.</p></body></html>';
|
|
134
|
+
|
|
135
|
+
html2pdf.insertFromHtmlString(html);
|
|
136
|
+
await html2pdf.convert(doc);
|
|
137
|
+
doc.save(outputPath.concat('_04.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
138
|
+
} catch (err) {
|
|
139
|
+
console.log(err);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
//--------------------------------------------------------------------------------
|
|
143
|
+
// Example 5) Set the location of the log file to be used during conversion.
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
147
|
+
const doc = await PDFNet.PDFDoc.create();
|
|
148
|
+
html2pdf.setLogFilePath('../TestFiles/Output/html2pdf.log');
|
|
149
|
+
html2pdf.insertFromUrl(host.concat(page0));
|
|
150
|
+
await html2pdf.convert(doc);
|
|
151
|
+
doc.save(outputPath.concat('_05.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
console.log(err);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
console.log('Test Complete!');
|
|
157
|
+
}
|
|
158
|
+
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
|
|
159
|
+
console.log('Error: ' + JSON.stringify(error));
|
|
160
|
+
}).then(function(){ return PDFNet.shutdown(); });
|
|
161
|
+
};
|
|
162
|
+
exports.runHTML2PDFTest();
|
|
163
|
+
})(exports);
|
|
164
|
+
// eslint-disable-next-line spaced-comment
|
|
165
165
|
//# sourceURL=HTML2PDFTest.js
|
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-2024 by Apryse Software 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
|
-
// This sample illustrates the basic text highlight capabilities of PDFNet.
|
|
11
|
-
// It simulates a full-text search engine that finds all occurrences of the word 'Federal'.
|
|
12
|
-
// It then highlights those words on the page.
|
|
13
|
-
//
|
|
14
|
-
// Note: The TextSearch class is the preferred solution for searching text within a single
|
|
15
|
-
// PDF file. TextExtractor provides search highlighting capabilities where a large number
|
|
16
|
-
// of documents are indexed using a 3rd party search engine.
|
|
17
|
-
((exports) => {
|
|
18
|
-
|
|
19
|
-
exports.runHighlightsTest = async () => {
|
|
20
|
-
const main = async () => {
|
|
21
|
-
// eslint-disable-next-line no-unused-vars
|
|
22
|
-
let ret = 0;
|
|
23
|
-
|
|
24
|
-
// Relative path to the folder containing test files.
|
|
25
|
-
const inputPath = '../TestFiles/';
|
|
26
|
-
const outputPath = '../TestFiles/Output/';
|
|
27
|
-
const inputFilename = 'paragraphs_and_tables.pdf';
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
await PDFNet.startDeallocateStack();
|
|
31
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + inputFilename);
|
|
32
|
-
doc.initSecurityHandler();
|
|
33
|
-
|
|
34
|
-
const page = await doc.getPage(1);
|
|
35
|
-
|
|
36
|
-
if (page.id === '0') {
|
|
37
|
-
console.log('Page not found.');
|
|
38
|
-
return 1;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const txt = await PDFNet.TextExtractor.create();
|
|
42
|
-
txt.begin(page);
|
|
43
|
-
|
|
44
|
-
// Do not dehyphenate; that would interfere with character offsets
|
|
45
|
-
const dehyphen = false;
|
|
46
|
-
// Retrieve the page text
|
|
47
|
-
const pageText = await txt.getAsText(dehyphen);
|
|
48
|
-
|
|
49
|
-
// Simulating a full-text search engine that finds all occurrences of the word 'Federal'.
|
|
50
|
-
// In a real application, plug in your own search engine here.
|
|
51
|
-
const searchText = 'Federal';
|
|
52
|
-
let charRanges = [];
|
|
53
|
-
let ofs = pageText.indexOf(searchText);
|
|
54
|
-
while (ofs >= 0) {
|
|
55
|
-
const range = { index: ofs, length: searchText.length };
|
|
56
|
-
charRanges.push(range); // character offset + length
|
|
57
|
-
ofs = pageText.indexOf(searchText, ofs + 1);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Retrieve Highlights object and apply annotations to the page
|
|
61
|
-
const hlts = await txt.getHighlights(charRanges);
|
|
62
|
-
await hlts.begin(doc);
|
|
63
|
-
while ((await hlts.hasNext())) {
|
|
64
|
-
const curPage = await doc.getPage((await hlts.getCurrentPageNumber()));
|
|
65
|
-
const quadArr = await hlts.getCurrentQuads();
|
|
66
|
-
for (let i = 0; i < quadArr.length; ++i) {
|
|
67
|
-
const currQuad = quadArr[i];
|
|
68
|
-
const x1 = Math.min(Math.min(Math.min(currQuad.p1x, currQuad.p2x), currQuad.p3x), currQuad.p4x);
|
|
69
|
-
const x2 = Math.max(Math.max(Math.max(currQuad.p1x, currQuad.p2x), currQuad.p3x), currQuad.p4x);
|
|
70
|
-
const y1 = Math.min(Math.min(Math.min(currQuad.p1y, currQuad.p2y), currQuad.p3y), currQuad.p4y);
|
|
71
|
-
const y2 = Math.max(Math.max(Math.max(currQuad.p1y, currQuad.p2y), currQuad.p3y), currQuad.p4y);
|
|
72
|
-
|
|
73
|
-
const highlight = await PDFNet.HighlightAnnot.create(doc, (await PDFNet.Rect.init(x1, y1, x2, y2)));
|
|
74
|
-
await highlight.refreshAppearance();
|
|
75
|
-
await curPage.annotPushBack(highlight);
|
|
76
|
-
|
|
77
|
-
console.log('[' + x1.toFixed(2) + ', ' + y1.toFixed(2) + ', ' + x2.toFixed(2) + ', ' + y2.toFixed(2) + ']');
|
|
78
|
-
}
|
|
79
|
-
hlts.next();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Output highlighted PDF doc
|
|
83
|
-
await doc.save(outputPath + 'search_highlights.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
84
|
-
|
|
85
|
-
await PDFNet.endDeallocateStack();
|
|
86
|
-
} catch (err) {
|
|
87
|
-
console.log(err);
|
|
88
|
-
console.log(err.stack);
|
|
89
|
-
ret = 1;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
|
|
93
|
-
};
|
|
94
|
-
exports.runHighlightsTest();
|
|
95
|
-
})(exports);
|
|
96
|
-
// eslint-disable-next-line spaced-comment
|
|
97
|
-
//# sourceURL=HighlightsTest.js
|
|
1
|
+
//---------------------------------------------------------------------------------------
|
|
2
|
+
// Copyright (c) 2001-2024 by Apryse Software 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
|
+
// This sample illustrates the basic text highlight capabilities of PDFNet.
|
|
11
|
+
// It simulates a full-text search engine that finds all occurrences of the word 'Federal'.
|
|
12
|
+
// It then highlights those words on the page.
|
|
13
|
+
//
|
|
14
|
+
// Note: The TextSearch class is the preferred solution for searching text within a single
|
|
15
|
+
// PDF file. TextExtractor provides search highlighting capabilities where a large number
|
|
16
|
+
// of documents are indexed using a 3rd party search engine.
|
|
17
|
+
((exports) => {
|
|
18
|
+
|
|
19
|
+
exports.runHighlightsTest = async () => {
|
|
20
|
+
const main = async () => {
|
|
21
|
+
// eslint-disable-next-line no-unused-vars
|
|
22
|
+
let ret = 0;
|
|
23
|
+
|
|
24
|
+
// Relative path to the folder containing test files.
|
|
25
|
+
const inputPath = '../TestFiles/';
|
|
26
|
+
const outputPath = '../TestFiles/Output/';
|
|
27
|
+
const inputFilename = 'paragraphs_and_tables.pdf';
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
await PDFNet.startDeallocateStack();
|
|
31
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + inputFilename);
|
|
32
|
+
doc.initSecurityHandler();
|
|
33
|
+
|
|
34
|
+
const page = await doc.getPage(1);
|
|
35
|
+
|
|
36
|
+
if (page.id === '0') {
|
|
37
|
+
console.log('Page not found.');
|
|
38
|
+
return 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const txt = await PDFNet.TextExtractor.create();
|
|
42
|
+
txt.begin(page);
|
|
43
|
+
|
|
44
|
+
// Do not dehyphenate; that would interfere with character offsets
|
|
45
|
+
const dehyphen = false;
|
|
46
|
+
// Retrieve the page text
|
|
47
|
+
const pageText = await txt.getAsText(dehyphen);
|
|
48
|
+
|
|
49
|
+
// Simulating a full-text search engine that finds all occurrences of the word 'Federal'.
|
|
50
|
+
// In a real application, plug in your own search engine here.
|
|
51
|
+
const searchText = 'Federal';
|
|
52
|
+
let charRanges = [];
|
|
53
|
+
let ofs = pageText.indexOf(searchText);
|
|
54
|
+
while (ofs >= 0) {
|
|
55
|
+
const range = { index: ofs, length: searchText.length };
|
|
56
|
+
charRanges.push(range); // character offset + length
|
|
57
|
+
ofs = pageText.indexOf(searchText, ofs + 1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Retrieve Highlights object and apply annotations to the page
|
|
61
|
+
const hlts = await txt.getHighlights(charRanges);
|
|
62
|
+
await hlts.begin(doc);
|
|
63
|
+
while ((await hlts.hasNext())) {
|
|
64
|
+
const curPage = await doc.getPage((await hlts.getCurrentPageNumber()));
|
|
65
|
+
const quadArr = await hlts.getCurrentQuads();
|
|
66
|
+
for (let i = 0; i < quadArr.length; ++i) {
|
|
67
|
+
const currQuad = quadArr[i];
|
|
68
|
+
const x1 = Math.min(Math.min(Math.min(currQuad.p1x, currQuad.p2x), currQuad.p3x), currQuad.p4x);
|
|
69
|
+
const x2 = Math.max(Math.max(Math.max(currQuad.p1x, currQuad.p2x), currQuad.p3x), currQuad.p4x);
|
|
70
|
+
const y1 = Math.min(Math.min(Math.min(currQuad.p1y, currQuad.p2y), currQuad.p3y), currQuad.p4y);
|
|
71
|
+
const y2 = Math.max(Math.max(Math.max(currQuad.p1y, currQuad.p2y), currQuad.p3y), currQuad.p4y);
|
|
72
|
+
|
|
73
|
+
const highlight = await PDFNet.HighlightAnnot.create(doc, (await PDFNet.Rect.init(x1, y1, x2, y2)));
|
|
74
|
+
await highlight.refreshAppearance();
|
|
75
|
+
await curPage.annotPushBack(highlight);
|
|
76
|
+
|
|
77
|
+
console.log('[' + x1.toFixed(2) + ', ' + y1.toFixed(2) + ', ' + x2.toFixed(2) + ', ' + y2.toFixed(2) + ']');
|
|
78
|
+
}
|
|
79
|
+
hlts.next();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Output highlighted PDF doc
|
|
83
|
+
await doc.save(outputPath + 'search_highlights.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
84
|
+
|
|
85
|
+
await PDFNet.endDeallocateStack();
|
|
86
|
+
} catch (err) {
|
|
87
|
+
console.log(err);
|
|
88
|
+
console.log(err.stack);
|
|
89
|
+
ret = 1;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
|
|
93
|
+
};
|
|
94
|
+
exports.runHighlightsTest();
|
|
95
|
+
})(exports);
|
|
96
|
+
// eslint-disable-next-line spaced-comment
|
|
97
|
+
//# sourceURL=HighlightsTest.js
|