@pdftron/pdfnet-node-samples 9.4.2 → 9.5.0-2-beta-1
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/package.json +18 -18
- package/readme.md +12 -12
- package/samples/AddImageTest/AddImageTest.js +2 -2
- package/samples/AdvancedImagingTest/AdvancedImagingTest.js +3 -3
- package/samples/AnnotationTest/AnnotationTest.js +2 -2
- package/samples/BookmarkTest/BookmarkTest.js +2 -2
- package/samples/CAD2PDFTest/CAD2PDFTest.js +79 -79
- package/samples/ContentReplacerTest/ContentReplacerTest.js +2 -2
- package/samples/ConvertTest/ConvertTest.js +270 -256
- package/samples/DataExtractionTest/DataExtractionTest.js +180 -0
- package/samples/DigitalSignaturesTest/DigitalSignaturesTest.js +526 -526
- package/samples/ElementBuilderTest/ElementBuilderTest.js +2 -2
- package/samples/ElementEditTest/ElementEditTest.js +2 -2
- package/samples/ElementReaderAdvTest/ElementReaderAdvTest.js +2 -2
- package/samples/ElementReaderTest/ElementReaderTest.js +2 -2
- package/samples/EncTest/EncTest.js +2 -2
- package/samples/FDFTest/FDFTest.js +218 -218
- package/samples/HTML2PDFTest/HTML2PDFTest.js +165 -165
- package/samples/HighlightsTest/HighlightsTest.js +2 -2
- package/samples/ImageExtractTest/ImageExtractTest.js +129 -129
- package/samples/ImpositionTest/ImpositionTest.js +86 -86
- package/samples/InteractiveFormsTest/InteractiveFormsTest.js +381 -381
- package/samples/JBIG2Test/JBIG2Test.js +88 -88
- package/samples/LogicalStructureTest/LogicalStructureTest.js +2 -2
- package/samples/OCRTest/OCRTest.js +234 -234
- package/samples/OfficeTemplateTest/OfficeTemplateTest.js +79 -77
- package/samples/OfficeToPDFTest/OfficeToPDFTest.js +125 -125
- package/samples/OptimizerTest/OptimizerTest.js +191 -191
- package/samples/PDF2HtmlTest/PDF2HtmlTest.js +3 -3
- package/samples/PDF2OfficeTest/PDF2OfficeTest.js +3 -3
- package/samples/PDFATest/PDFATest.js +2 -2
- package/samples/PDFDocMemoryTest/PDFDocMemoryTest.js +84 -84
- package/samples/PDFDrawTest/PDFDrawTest.js +2 -2
- package/samples/PDFLayersTest/PDFLayersTest.js +2 -2
- package/samples/PDFPackageTest/PDFPackageTest.js +111 -111
- package/samples/PDFPageTest/PDFPageTest.js +2 -2
- package/samples/PDFRedactTest/PDFRedactTest.js +2 -2
- package/samples/PageLabelsTest/PageLabelsTest.js +138 -138
- package/samples/PatternTest/PatternTest.js +226 -226
- package/samples/RectTest/RectTest.js +2 -2
- package/samples/SDFTest/SDFTest.js +3 -4
- package/samples/StamperTest/StamperTest.js +2 -2
- package/samples/TextExtractTest/TextExtractTest.js +2 -2
- package/samples/TextSearchTest/TextSearchTest.js +2 -2
- package/samples/U3DTest/U3DTest.js +104 -104
- package/samples/UndoRedoTest/UndoRedoTest.js +2 -2
- package/samples/UnicodeWriteTest/UnicodeWriteTest.js +2 -2
- package/samples/WebViewerConvertTest/WebViewerConvertTest.js +135 -135
- package/samples/runall.bat +6 -5
- package/samples/runall.sh +4 -5
- package/samples/TestFiles/BusinessCardTemplate.pdf +0 -0
- package/samples/TestFiles/Fishermen.docx +0 -0
- package/samples/TestFiles/Font_licenses.txt +0 -140
- package/samples/TestFiles/GlobalSignRootForTST.cer +0 -0
- package/samples/TestFiles/License.txt +0 -1
- package/samples/TestFiles/Misc-Fixed.pfa +0 -1166
- package/samples/TestFiles/NotoSans_with_hindi.ttf +0 -0
- package/samples/TestFiles/Output/empty +0 -1
- package/samples/TestFiles/SHA-2 Root USERTrust RSA CA Sectigo timestamping.crt +0 -34
- package/samples/TestFiles/SYH_Letter.docx +0 -0
- package/samples/TestFiles/TigerText.pdf +0 -0
- package/samples/TestFiles/US061222892-a.pdf +0 -0
- package/samples/TestFiles/butterfly.png +0 -0
- package/samples/TestFiles/credit card numbers.pdf +0 -0
- package/samples/TestFiles/dice.jpg +0 -0
- package/samples/TestFiles/dice.u3d +0 -0
- package/samples/TestFiles/doc_to_sign.pdf +0 -0
- package/samples/TestFiles/factsheet_Arabic.docx +0 -0
- package/samples/TestFiles/fish.pdf +0 -0
- package/samples/TestFiles/font.ttf +0 -0
- package/samples/TestFiles/form1.pdf +1 -245
- package/samples/TestFiles/form1_annots.xfdf +0 -34
- package/samples/TestFiles/form1_data.fdf +0 -4
- package/samples/TestFiles/form1_data.xfdf +0 -140
- package/samples/TestFiles/grayscale.tif +0 -0
- package/samples/TestFiles/hindi_sample_utf16le.txt +0 -0
- package/samples/TestFiles/imagemask.dat +0 -32
- package/samples/TestFiles/logo_red.png +0 -0
- package/samples/TestFiles/lorem_ipsum.pdf +0 -0
- package/samples/TestFiles/multipage.tif +0 -0
- package/samples/TestFiles/my_stream.txt +0 -2310
- package/samples/TestFiles/newsletter.pdf +0 -0
- package/samples/TestFiles/newsletter.xod +0 -0
- package/samples/TestFiles/numbered.pdf +0 -0
- package/samples/TestFiles/op_blend_test.pdf +0 -1498
- package/samples/TestFiles/palm.jp2 +0 -0
- package/samples/TestFiles/paragraphs_and_tables.pdf +0 -0
- package/samples/TestFiles/pdfnet.gif +0 -0
- package/samples/TestFiles/pdftron.bmp +0 -0
- package/samples/TestFiles/pdftron.cer +0 -0
- package/samples/TestFiles/pdftron.pfx +0 -0
- package/samples/TestFiles/pdftron_smart_substitution.plugin +0 -0
- package/samples/TestFiles/peppers.jpg +0 -0
- package/samples/TestFiles/signature.jpg +0 -0
- package/samples/TestFiles/simple-emf.emf +0 -0
- package/samples/TestFiles/simple-excel_2007.xlsx +0 -0
- package/samples/TestFiles/simple-outlook.msg +0 -0
- package/samples/TestFiles/simple-powerpoint_2007.pptx +0 -0
- package/samples/TestFiles/simple-publisher.pub +0 -0
- package/samples/TestFiles/simple-rtf.rtf +0 -224
- package/samples/TestFiles/simple-text.txt +0 -61
- package/samples/TestFiles/simple-visio.vsd +0 -0
- package/samples/TestFiles/simple-webpage.html +0 -731
- package/samples/TestFiles/simple-webpage.mht +0 -6972
- package/samples/TestFiles/simple-webpage_files/colorschememapping.xml +0 -2
- package/samples/TestFiles/simple-webpage_files/filelist.xml +0 -14
- package/samples/TestFiles/simple-webpage_files/image001.gif +0 -0
- package/samples/TestFiles/simple-webpage_files/image002.png +0 -0
- package/samples/TestFiles/simple-webpage_files/image003.jpg +0 -0
- package/samples/TestFiles/simple-webpage_files/image004.emz +0 -0
- package/samples/TestFiles/simple-webpage_files/image005.gif +0 -0
- package/samples/TestFiles/simple-webpage_files/image006.png +0 -0
- package/samples/TestFiles/simple-webpage_files/image007.gif +0 -0
- package/samples/TestFiles/simple-webpage_files/oledata.mso +0 -0
- package/samples/TestFiles/simple-webpage_files/themedata.thmx +0 -0
- package/samples/TestFiles/simple-word_2007.docx +0 -0
- package/samples/TestFiles/simple-xps.xps +0 -0
- package/samples/TestFiles/tagged.pdf +0 -0
- package/samples/TestFiles/the_rime_of_the_ancient_mariner.docx +0 -0
- package/samples/TestFiles/tiger.pdf +0 -0
- package/samples/TestFiles/waiver.pdf +0 -0
- package/samples/TestFiles/waiver_withApprovalField.pdf +0 -0
- package/samples/TestFiles/waiver_withApprovalField_certified.pdf +1 -424
- package/samples/TestFiles/waiver_withApprovalField_certified_approved.pdf +1 -466
|
@@ -1,166 +1,166 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
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('
|
|
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://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.
|
|
39
|
-
await PDFNet.HTML2PDF.setModulePath('
|
|
40
|
-
|
|
41
|
-
if(!(await PDFNet.HTML2PDF.isModuleAvailable())) {
|
|
42
|
-
console.log('Unable to run HTML2PDFTest: PDFTron SDK HTML2PDF module not available.');
|
|
43
|
-
console.log('---------------------------------------------------------------');
|
|
44
|
-
console.log('The HTML2PDF module is an optional add-on, available for download');
|
|
45
|
-
console.log('at https://www.pdftron.com/. If you have already downloaded this');
|
|
46
|
-
console.log('module, ensure that the SDK is able to find the required files');
|
|
47
|
-
console.log('using the HTML2PDF.setModulePath() function.');
|
|
48
|
-
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
//--------------------------------------------------------------------------------
|
|
53
|
-
// Example 1) Simple conversion of a web page to a PDF doc.
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
57
|
-
const doc = await PDFNet.PDFDoc.create();
|
|
58
|
-
|
|
59
|
-
html2pdf.insertFromUrl(host.concat(page0));
|
|
60
|
-
// now convert a web page, sending generated PDF pages to doc
|
|
61
|
-
if (await html2pdf.convert(doc)) {
|
|
62
|
-
doc.save(outputPath.concat('_01.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
63
|
-
} else {
|
|
64
|
-
console.log('Conversion failed.');
|
|
65
|
-
}
|
|
66
|
-
} catch (err) {
|
|
67
|
-
console.log(err);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
//--------------------------------------------------------------------------------
|
|
71
|
-
// Example 2) Modify the settings of the generated PDF pages and attach to an
|
|
72
|
-
// existing PDF document.
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
// open the existing PDF, and initialize the security handler
|
|
76
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath('../TestFiles/numbered.pdf');
|
|
77
|
-
await doc.initSecurityHandler();
|
|
78
|
-
|
|
79
|
-
// create the HTML2PDF converter object and modify the output of the PDF pages
|
|
80
|
-
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
81
|
-
html2pdf.setPaperSize(PDFNet.PrinterMode.PaperSize.e_11x17);
|
|
82
|
-
|
|
83
|
-
// insert the web page to convert
|
|
84
|
-
html2pdf.insertFromUrl(host.concat(page0));
|
|
85
|
-
|
|
86
|
-
// convert the web page, appending generated PDF pages to doc
|
|
87
|
-
if (await html2pdf.convert(doc)) {
|
|
88
|
-
doc.save(outputPath.concat('_02.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
89
|
-
} else {
|
|
90
|
-
console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
|
|
91
|
-
console.log(await html2pdf.getLog());
|
|
92
|
-
}
|
|
93
|
-
} catch (err) {
|
|
94
|
-
console.log(err);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
//--------------------------------------------------------------------------------
|
|
98
|
-
// Example 3) Convert multiple web pages
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
// convert page 0 into pdf
|
|
102
|
-
const doc = await PDFNet.PDFDoc.create();
|
|
103
|
-
|
|
104
|
-
const converter = await PDFNet.HTML2PDF.create();
|
|
105
|
-
|
|
106
|
-
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>';
|
|
107
|
-
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>';
|
|
108
|
-
converter.setHeader(header);
|
|
109
|
-
converter.setFooter(footer);
|
|
110
|
-
converter.setMargins('1cm', '2cm', '.5cm', '1.5cm');
|
|
111
|
-
const settings = await PDFNet.HTML2PDF.WebPageSettings.create();
|
|
112
|
-
await settings.setZoom(0.5);
|
|
113
|
-
converter.insertFromUrl2(host.concat(page0), settings);
|
|
114
|
-
const is_conversion_0_successful = await converter.convert(doc);
|
|
115
|
-
|
|
116
|
-
// convert page 1 with the same settings, appending generated PDF pages to doc
|
|
117
|
-
converter.insertFromUrl2(host.concat(page1), settings);
|
|
118
|
-
const is_conversion_1_successful = await converter.convert(doc);
|
|
119
|
-
|
|
120
|
-
// convert page 2 with different settings, appending generated PDF pages to doc
|
|
121
|
-
const another_converter = await PDFNet.HTML2PDF.create();
|
|
122
|
-
another_converter.setLandscape(true);
|
|
123
|
-
const another_settings = await PDFNet.HTML2PDF.WebPageSettings.create();
|
|
124
|
-
another_settings.setPrintBackground(false);
|
|
125
|
-
another_converter.insertFromUrl2(host.concat(page2), another_settings);
|
|
126
|
-
const is_conversion_2_successful = await another_converter.convert(doc);
|
|
127
|
-
|
|
128
|
-
if(is_conversion_0_successful && is_conversion_1_successful && is_conversion_2_successful) {
|
|
129
|
-
doc.save(outputPath.concat('_03.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
130
|
-
} else {
|
|
131
|
-
console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
|
|
132
|
-
console.log(await html2pdf.getLog());
|
|
133
|
-
}
|
|
134
|
-
} catch (err) {
|
|
135
|
-
console.log(err);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
//--------------------------------------------------------------------------------
|
|
139
|
-
// Example 4) Convert HTML string to PDF.
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
143
|
-
const doc = await PDFNet.PDFDoc.create();
|
|
144
|
-
const html = '<html><body><h1>Heading</h1><p>Paragraph.</p></body></html>';
|
|
145
|
-
|
|
146
|
-
html2pdf.insertFromHtmlString(html);
|
|
147
|
-
if (await html2pdf.convert(doc)) {
|
|
148
|
-
doc.save(outputPath.concat('_04.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
149
|
-
} else {
|
|
150
|
-
console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
|
|
151
|
-
console.log(await html2pdf.getLog());
|
|
152
|
-
}
|
|
153
|
-
} catch (err) {
|
|
154
|
-
console.log(err);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
console.log('Test Complete!');
|
|
158
|
-
}
|
|
159
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
|
|
160
|
-
console.log('Error: ' + JSON.stringify(error));
|
|
161
|
-
}).then(function(){ return PDFNet.shutdown(); });
|
|
162
|
-
};
|
|
163
|
-
exports.runHTML2PDFTest();
|
|
164
|
-
})(exports);
|
|
165
|
-
// 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
|
+
// 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('../lib/pdfnet.js');
|
|
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://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.
|
|
39
|
+
await PDFNet.HTML2PDF.setModulePath('../lib/');
|
|
40
|
+
|
|
41
|
+
if(!(await PDFNet.HTML2PDF.isModuleAvailable())) {
|
|
42
|
+
console.log('Unable to run HTML2PDFTest: PDFTron SDK HTML2PDF module not available.');
|
|
43
|
+
console.log('---------------------------------------------------------------');
|
|
44
|
+
console.log('The HTML2PDF module is an optional add-on, available for download');
|
|
45
|
+
console.log('at https://www.pdftron.com/. If you have already downloaded this');
|
|
46
|
+
console.log('module, ensure that the SDK is able to find the required files');
|
|
47
|
+
console.log('using the HTML2PDF.setModulePath() function.');
|
|
48
|
+
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//--------------------------------------------------------------------------------
|
|
53
|
+
// Example 1) Simple conversion of a web page to a PDF doc.
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
57
|
+
const doc = await PDFNet.PDFDoc.create();
|
|
58
|
+
|
|
59
|
+
html2pdf.insertFromUrl(host.concat(page0));
|
|
60
|
+
// now convert a web page, sending generated PDF pages to doc
|
|
61
|
+
if (await html2pdf.convert(doc)) {
|
|
62
|
+
doc.save(outputPath.concat('_01.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
63
|
+
} else {
|
|
64
|
+
console.log('Conversion failed.');
|
|
65
|
+
}
|
|
66
|
+
} catch (err) {
|
|
67
|
+
console.log(err);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//--------------------------------------------------------------------------------
|
|
71
|
+
// Example 2) Modify the settings of the generated PDF pages and attach to an
|
|
72
|
+
// existing PDF document.
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
// open the existing PDF, and initialize the security handler
|
|
76
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath('../TestFiles/numbered.pdf');
|
|
77
|
+
await doc.initSecurityHandler();
|
|
78
|
+
|
|
79
|
+
// create the HTML2PDF converter object and modify the output of the PDF pages
|
|
80
|
+
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
81
|
+
html2pdf.setPaperSize(PDFNet.PrinterMode.PaperSize.e_11x17);
|
|
82
|
+
|
|
83
|
+
// insert the web page to convert
|
|
84
|
+
html2pdf.insertFromUrl(host.concat(page0));
|
|
85
|
+
|
|
86
|
+
// convert the web page, appending generated PDF pages to doc
|
|
87
|
+
if (await html2pdf.convert(doc)) {
|
|
88
|
+
doc.save(outputPath.concat('_02.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
89
|
+
} else {
|
|
90
|
+
console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
|
|
91
|
+
console.log(await html2pdf.getLog());
|
|
92
|
+
}
|
|
93
|
+
} catch (err) {
|
|
94
|
+
console.log(err);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//--------------------------------------------------------------------------------
|
|
98
|
+
// Example 3) Convert multiple web pages
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
// convert page 0 into pdf
|
|
102
|
+
const doc = await PDFNet.PDFDoc.create();
|
|
103
|
+
|
|
104
|
+
const converter = await PDFNet.HTML2PDF.create();
|
|
105
|
+
|
|
106
|
+
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>';
|
|
107
|
+
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>';
|
|
108
|
+
converter.setHeader(header);
|
|
109
|
+
converter.setFooter(footer);
|
|
110
|
+
converter.setMargins('1cm', '2cm', '.5cm', '1.5cm');
|
|
111
|
+
const settings = await PDFNet.HTML2PDF.WebPageSettings.create();
|
|
112
|
+
await settings.setZoom(0.5);
|
|
113
|
+
converter.insertFromUrl2(host.concat(page0), settings);
|
|
114
|
+
const is_conversion_0_successful = await converter.convert(doc);
|
|
115
|
+
|
|
116
|
+
// convert page 1 with the same settings, appending generated PDF pages to doc
|
|
117
|
+
converter.insertFromUrl2(host.concat(page1), settings);
|
|
118
|
+
const is_conversion_1_successful = await converter.convert(doc);
|
|
119
|
+
|
|
120
|
+
// convert page 2 with different settings, appending generated PDF pages to doc
|
|
121
|
+
const another_converter = await PDFNet.HTML2PDF.create();
|
|
122
|
+
another_converter.setLandscape(true);
|
|
123
|
+
const another_settings = await PDFNet.HTML2PDF.WebPageSettings.create();
|
|
124
|
+
another_settings.setPrintBackground(false);
|
|
125
|
+
another_converter.insertFromUrl2(host.concat(page2), another_settings);
|
|
126
|
+
const is_conversion_2_successful = await another_converter.convert(doc);
|
|
127
|
+
|
|
128
|
+
if(is_conversion_0_successful && is_conversion_1_successful && is_conversion_2_successful) {
|
|
129
|
+
doc.save(outputPath.concat('_03.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
130
|
+
} else {
|
|
131
|
+
console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
|
|
132
|
+
console.log(await html2pdf.getLog());
|
|
133
|
+
}
|
|
134
|
+
} catch (err) {
|
|
135
|
+
console.log(err);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//--------------------------------------------------------------------------------
|
|
139
|
+
// Example 4) Convert HTML string to PDF.
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const html2pdf = await PDFNet.HTML2PDF.create();
|
|
143
|
+
const doc = await PDFNet.PDFDoc.create();
|
|
144
|
+
const html = '<html><body><h1>Heading</h1><p>Paragraph.</p></body></html>';
|
|
145
|
+
|
|
146
|
+
html2pdf.insertFromHtmlString(html);
|
|
147
|
+
if (await html2pdf.convert(doc)) {
|
|
148
|
+
doc.save(outputPath.concat('_04.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
149
|
+
} else {
|
|
150
|
+
console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
|
|
151
|
+
console.log(await html2pdf.getLog());
|
|
152
|
+
}
|
|
153
|
+
} catch (err) {
|
|
154
|
+
console.log(err);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
console.log('Test Complete!');
|
|
158
|
+
}
|
|
159
|
+
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
|
|
160
|
+
console.log('Error: ' + JSON.stringify(error));
|
|
161
|
+
}).then(function(){ return PDFNet.shutdown(); });
|
|
162
|
+
};
|
|
163
|
+
exports.runHTML2PDFTest();
|
|
164
|
+
})(exports);
|
|
165
|
+
// eslint-disable-next-line spaced-comment
|
|
166
166
|
//# sourceURL=HTML2PDFTest.js
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
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
|
|
|
6
6
|
|
|
7
|
-
const { PDFNet } = require('
|
|
7
|
+
const { PDFNet } = require('../lib/pdfnet.js');
|
|
8
8
|
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
9
9
|
|
|
10
10
|
// This sample illustrates the basic text highlight capabilities of PDFNet.
|
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
3
|
-
// Consult legal.txt regarding legal and license information.
|
|
4
|
-
//---------------------------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
//-----------------------------------------------------------------------------------
|
|
7
|
-
// This sample illustrates one approach to PDF image extraction
|
|
8
|
-
// using PDFNet.
|
|
9
|
-
//
|
|
10
|
-
// Note: Besides direct image export, you can also convert PDF images
|
|
11
|
-
// to GDI+ Bitmap, or extract uncompressed/compressed image data directly
|
|
12
|
-
// using element.GetImageData() (e.g. as illustrated in ElementReaderAdv
|
|
13
|
-
// sample project).
|
|
14
|
-
//-----------------------------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
const { PDFNet } = require('
|
|
17
|
-
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
18
|
-
|
|
19
|
-
((exports) => {
|
|
20
|
-
'use strict';
|
|
21
|
-
|
|
22
|
-
exports.runImageExtractTest = () => {
|
|
23
|
-
|
|
24
|
-
let image_counter = 0;
|
|
25
|
-
const outputPath = '../TestFiles/Output/';
|
|
26
|
-
|
|
27
|
-
const imageExtract = async (reader) => {
|
|
28
|
-
let element;
|
|
29
|
-
while ((element = await reader.next()) !== null) {
|
|
30
|
-
switch (await element.getType()) {
|
|
31
|
-
case PDFNet.Element.Type.e_image:
|
|
32
|
-
case PDFNet.Element.Type.e_inline_image:
|
|
33
|
-
console.log('--> Image: ' + ++image_counter);
|
|
34
|
-
console.log(' Width: ' + await element.getImageWidth());
|
|
35
|
-
console.log(' Height: ' + await element.getImageHeight());
|
|
36
|
-
console.log(' BPC: ' + await element.getBitsPerComponent());
|
|
37
|
-
|
|
38
|
-
const ctm = await element.getCTM();
|
|
39
|
-
let x2 = 1, y2 = 1;
|
|
40
|
-
const result = await ctm.mult(x2, y2);
|
|
41
|
-
x2 = result.x;
|
|
42
|
-
y2 = result.y;
|
|
43
|
-
console.log(' Coords: x1=' + ctm.m_h.toFixed(2) + ', y1=' + ctm.m_v.toFixed(2)
|
|
44
|
-
+ ', x2=' + x2.toFixed(2) + ', y2=' + y2.toFixed(2));
|
|
45
|
-
|
|
46
|
-
if (await element.getType() == PDFNet.Element.Type.e_image) {
|
|
47
|
-
const image = await PDFNet.Image.createFromObj(await element.getXObject());
|
|
48
|
-
image.export(outputPath + 'image_extract1_' + image_counter);
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
case PDFNet.Element.Type.e_form: // Process form XObjects
|
|
52
|
-
reader.formBegin();
|
|
53
|
-
await imageExtract(reader);
|
|
54
|
-
reader.end();
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const main = async () => {
|
|
61
|
-
|
|
62
|
-
// Example 1:
|
|
63
|
-
// Extract images by traversing the display list for
|
|
64
|
-
// every page. With this approach it is possible to obtain
|
|
65
|
-
// image positioning information and DPI.
|
|
66
|
-
try {
|
|
67
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath('../TestFiles/newsletter.pdf');
|
|
68
|
-
doc.initSecurityHandler();
|
|
69
|
-
|
|
70
|
-
const reader = await PDFNet.ElementReader.create();
|
|
71
|
-
const itr = await doc.getPageIterator(1);
|
|
72
|
-
// Read every page
|
|
73
|
-
for (itr; await itr.hasNext(); await itr.next()) {
|
|
74
|
-
const page = await itr.current();
|
|
75
|
-
reader.beginOnPage(page);
|
|
76
|
-
await imageExtract(reader);
|
|
77
|
-
reader.end();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
console.log('Done.');
|
|
81
|
-
} catch (err) {
|
|
82
|
-
console.log(err);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
console.log('----------------------------------------------------------------');
|
|
86
|
-
|
|
87
|
-
// Example 2:
|
|
88
|
-
// Extract images by scanning the low-level document.
|
|
89
|
-
try {
|
|
90
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath('../TestFiles/newsletter.pdf');
|
|
91
|
-
doc.initSecurityHandler();
|
|
92
|
-
image_counter = 0;
|
|
93
|
-
|
|
94
|
-
const cos_doc = await doc.getSDFDoc();
|
|
95
|
-
const num_objs = await cos_doc.xRefSize();
|
|
96
|
-
for (var i = 0; i < num_objs; i++) {
|
|
97
|
-
const obj = await cos_doc.getObj(i);
|
|
98
|
-
if (obj && !(await obj.isFree()) && await obj.isStream()) {
|
|
99
|
-
// Process only images
|
|
100
|
-
var itr = await obj.find('Type');
|
|
101
|
-
if (!(await itr.hasNext()) || await (await itr.value()).getName() !== 'XObject')
|
|
102
|
-
continue;
|
|
103
|
-
|
|
104
|
-
itr = await obj.find('Subtype');
|
|
105
|
-
if (!(await itr.hasNext()) || await (await itr.value()).getName() !== 'Image')
|
|
106
|
-
continue;
|
|
107
|
-
const image = await PDFNet.Image.createFromObj(obj);
|
|
108
|
-
console.log('--> Image: ' + ++image_counter);
|
|
109
|
-
console.log(' Width: ' + await image.getImageWidth());
|
|
110
|
-
console.log(' Height: ' + await image.getImageHeight());
|
|
111
|
-
console.log(' BPC: ' + await image.getBitsPerComponent());
|
|
112
|
-
|
|
113
|
-
image.export(outputPath + 'image_extract2_' + image_counter);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
console.log('Done.');
|
|
118
|
-
} catch (err) {
|
|
119
|
-
console.log(err);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
|
|
124
|
-
console.log('Error: ' + JSON.stringify(error));
|
|
125
|
-
}).then(function(){ return PDFNet.shutdown(); });
|
|
126
|
-
};
|
|
127
|
-
exports.runImageExtractTest();
|
|
128
|
-
})(exports);
|
|
129
|
-
// 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
|
+
// This sample illustrates one approach to PDF image extraction
|
|
8
|
+
// using PDFNet.
|
|
9
|
+
//
|
|
10
|
+
// Note: Besides direct image export, you can also convert PDF images
|
|
11
|
+
// to GDI+ Bitmap, or extract uncompressed/compressed image data directly
|
|
12
|
+
// using element.GetImageData() (e.g. as illustrated in ElementReaderAdv
|
|
13
|
+
// sample project).
|
|
14
|
+
//-----------------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
const { PDFNet } = require('../lib/pdfnet.js');
|
|
17
|
+
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
18
|
+
|
|
19
|
+
((exports) => {
|
|
20
|
+
'use strict';
|
|
21
|
+
|
|
22
|
+
exports.runImageExtractTest = () => {
|
|
23
|
+
|
|
24
|
+
let image_counter = 0;
|
|
25
|
+
const outputPath = '../TestFiles/Output/';
|
|
26
|
+
|
|
27
|
+
const imageExtract = async (reader) => {
|
|
28
|
+
let element;
|
|
29
|
+
while ((element = await reader.next()) !== null) {
|
|
30
|
+
switch (await element.getType()) {
|
|
31
|
+
case PDFNet.Element.Type.e_image:
|
|
32
|
+
case PDFNet.Element.Type.e_inline_image:
|
|
33
|
+
console.log('--> Image: ' + ++image_counter);
|
|
34
|
+
console.log(' Width: ' + await element.getImageWidth());
|
|
35
|
+
console.log(' Height: ' + await element.getImageHeight());
|
|
36
|
+
console.log(' BPC: ' + await element.getBitsPerComponent());
|
|
37
|
+
|
|
38
|
+
const ctm = await element.getCTM();
|
|
39
|
+
let x2 = 1, y2 = 1;
|
|
40
|
+
const result = await ctm.mult(x2, y2);
|
|
41
|
+
x2 = result.x;
|
|
42
|
+
y2 = result.y;
|
|
43
|
+
console.log(' Coords: x1=' + ctm.m_h.toFixed(2) + ', y1=' + ctm.m_v.toFixed(2)
|
|
44
|
+
+ ', x2=' + x2.toFixed(2) + ', y2=' + y2.toFixed(2));
|
|
45
|
+
|
|
46
|
+
if (await element.getType() == PDFNet.Element.Type.e_image) {
|
|
47
|
+
const image = await PDFNet.Image.createFromObj(await element.getXObject());
|
|
48
|
+
image.export(outputPath + 'image_extract1_' + image_counter);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case PDFNet.Element.Type.e_form: // Process form XObjects
|
|
52
|
+
reader.formBegin();
|
|
53
|
+
await imageExtract(reader);
|
|
54
|
+
reader.end();
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const main = async () => {
|
|
61
|
+
|
|
62
|
+
// Example 1:
|
|
63
|
+
// Extract images by traversing the display list for
|
|
64
|
+
// every page. With this approach it is possible to obtain
|
|
65
|
+
// image positioning information and DPI.
|
|
66
|
+
try {
|
|
67
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath('../TestFiles/newsletter.pdf');
|
|
68
|
+
doc.initSecurityHandler();
|
|
69
|
+
|
|
70
|
+
const reader = await PDFNet.ElementReader.create();
|
|
71
|
+
const itr = await doc.getPageIterator(1);
|
|
72
|
+
// Read every page
|
|
73
|
+
for (itr; await itr.hasNext(); await itr.next()) {
|
|
74
|
+
const page = await itr.current();
|
|
75
|
+
reader.beginOnPage(page);
|
|
76
|
+
await imageExtract(reader);
|
|
77
|
+
reader.end();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
console.log('Done.');
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.log(err);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log('----------------------------------------------------------------');
|
|
86
|
+
|
|
87
|
+
// Example 2:
|
|
88
|
+
// Extract images by scanning the low-level document.
|
|
89
|
+
try {
|
|
90
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath('../TestFiles/newsletter.pdf');
|
|
91
|
+
doc.initSecurityHandler();
|
|
92
|
+
image_counter = 0;
|
|
93
|
+
|
|
94
|
+
const cos_doc = await doc.getSDFDoc();
|
|
95
|
+
const num_objs = await cos_doc.xRefSize();
|
|
96
|
+
for (var i = 0; i < num_objs; i++) {
|
|
97
|
+
const obj = await cos_doc.getObj(i);
|
|
98
|
+
if (obj && !(await obj.isFree()) && await obj.isStream()) {
|
|
99
|
+
// Process only images
|
|
100
|
+
var itr = await obj.find('Type');
|
|
101
|
+
if (!(await itr.hasNext()) || await (await itr.value()).getName() !== 'XObject')
|
|
102
|
+
continue;
|
|
103
|
+
|
|
104
|
+
itr = await obj.find('Subtype');
|
|
105
|
+
if (!(await itr.hasNext()) || await (await itr.value()).getName() !== 'Image')
|
|
106
|
+
continue;
|
|
107
|
+
const image = await PDFNet.Image.createFromObj(obj);
|
|
108
|
+
console.log('--> Image: ' + ++image_counter);
|
|
109
|
+
console.log(' Width: ' + await image.getImageWidth());
|
|
110
|
+
console.log(' Height: ' + await image.getImageHeight());
|
|
111
|
+
console.log(' BPC: ' + await image.getBitsPerComponent());
|
|
112
|
+
|
|
113
|
+
image.export(outputPath + 'image_extract2_' + image_counter);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log('Done.');
|
|
118
|
+
} catch (err) {
|
|
119
|
+
console.log(err);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
|
|
124
|
+
console.log('Error: ' + JSON.stringify(error));
|
|
125
|
+
}).then(function(){ return PDFNet.shutdown(); });
|
|
126
|
+
};
|
|
127
|
+
exports.runImageExtractTest();
|
|
128
|
+
})(exports);
|
|
129
|
+
// eslint-disable-next-line spaced-comment
|
|
130
130
|
//# sourceURL=ImageExtractTest.js
|