@pdftron/pdfnet-node-samples 9.4.2 → 9.5.0-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/runall.bat +12 -12
- package/samples/AddImageTest/AddImageTest.js +0 -116
- package/samples/AdvancedImagingTest/AdvancedImagingTest.js +0 -78
- package/samples/AnnotationTest/AnnotationTest.js +0 -642
- package/samples/BookmarkTest/BookmarkTest.js +0 -220
- package/samples/CAD2PDFTest/CAD2PDFTest.js +0 -80
- package/samples/ContentReplacerTest/ContentReplacerTest.js +0 -75
- package/samples/ConvertTest/ConvertTest.js +0 -256
- package/samples/DigitalSignaturesTest/DigitalSignaturesTest.js +0 -527
- package/samples/ElementBuilderTest/ElementBuilderTest.js +0 -514
- package/samples/ElementEditTest/ElementEditTest.js +0 -111
- package/samples/ElementReaderAdvTest/ElementReaderAdvTest.js +0 -305
- package/samples/ElementReaderTest/ElementReaderTest.js +0 -77
- package/samples/EncTest/EncTest.js +0 -176
- package/samples/FDFTest/FDFTest.js +0 -219
- package/samples/HTML2PDFTest/HTML2PDFTest.js +0 -166
- package/samples/HighlightsTest/HighlightsTest.js +0 -97
- package/samples/ImageExtractTest/ImageExtractTest.js +0 -130
- package/samples/ImpositionTest/ImpositionTest.js +0 -87
- package/samples/InteractiveFormsTest/InteractiveFormsTest.js +0 -382
- package/samples/JBIG2Test/JBIG2Test.js +0 -89
- package/samples/LicenseKey/LicenseKey.js +0 -11
- package/samples/LogicalStructureTest/LogicalStructureTest.js +0 -251
- package/samples/OCRTest/OCRTest.js +0 -235
- package/samples/OfficeTemplateTest/OfficeTemplateTest.js +0 -77
- package/samples/OfficeToPDFTest/OfficeToPDFTest.js +0 -125
- package/samples/OptimizerTest/OptimizerTest.js +0 -192
- package/samples/PDF2HtmlTest/PDF2HtmlTest.js +0 -123
- package/samples/PDF2OfficeTest/PDF2OfficeTest.js +0 -158
- package/samples/PDFATest/PDFATest.js +0 -85
- package/samples/PDFDocMemoryTest/PDFDocMemoryTest.js +0 -85
- package/samples/PDFDrawTest/PDFDrawTest.js +0 -306
- package/samples/PDFLayersTest/PDFLayersTest.js +0 -295
- package/samples/PDFPackageTest/PDFPackageTest.js +0 -112
- package/samples/PDFPageTest/PDFPageTest.js +0 -190
- package/samples/PDFRedactTest/PDFRedactTest.js +0 -75
- package/samples/PageLabelsTest/PageLabelsTest.js +0 -139
- package/samples/PatternTest/PatternTest.js +0 -227
- package/samples/RectTest/RectTest.js +0 -41
- package/samples/SDFTest/SDFTest.js +0 -89
- package/samples/StamperTest/StamperTest.js +0 -256
- 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
- package/samples/TextExtractTest/TextExtractTest.js +0 -287
- package/samples/TextSearchTest/TextSearchTest.js +0 -122
- package/samples/U3DTest/U3DTest.js +0 -105
- package/samples/UndoRedoTest/UndoRedoTest.js +0 -101
- package/samples/UnicodeWriteTest/UnicodeWriteTest.js +0 -174
- package/samples/WebViewerConvertTest/WebViewerConvertTest.js +0 -136
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-2022 by PDFTron Systems Inc. All Rights Reserved.
|
|
3
|
-
// Consult legal.txt regarding legal and license information.
|
|
4
|
-
//---------------------------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
//---------------------------------------------------------------------------------------
|
|
7
|
-
// PDFNet includes a full support for FDF (Forms Data Format) and capability to merge/extract
|
|
8
|
-
// forms data (FDF) with/from PDF. This sample illustrates basic FDF merge/extract functionality
|
|
9
|
-
// available in PDFNet.
|
|
10
|
-
//---------------------------------------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
13
|
-
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
14
|
-
|
|
15
|
-
((exports) => {
|
|
16
|
-
|
|
17
|
-
exports.runFDFTest = () => {
|
|
18
|
-
const main = async () => {
|
|
19
|
-
const inputPath = '../TestFiles/';
|
|
20
|
-
const outputPath = '../TestFiles/Output/';
|
|
21
|
-
|
|
22
|
-
// Example 1)
|
|
23
|
-
// Iterate over all form fields in the document. Display all field names.
|
|
24
|
-
try {
|
|
25
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'form1.pdf');
|
|
26
|
-
doc.initSecurityHandler();
|
|
27
|
-
|
|
28
|
-
for (const itr = await doc.getFieldIteratorBegin(); await itr.hasNext(); itr.next()) {
|
|
29
|
-
const field = await itr.current();
|
|
30
|
-
console.log('Field name: ' + await field.getName());
|
|
31
|
-
console.log('Field partial name: ' + await field.getPartialName());
|
|
32
|
-
|
|
33
|
-
switch (await field.getType()) {
|
|
34
|
-
case PDFNet.Field.Type.e_button:
|
|
35
|
-
console.log('Field type: Button');
|
|
36
|
-
break;
|
|
37
|
-
case PDFNet.Field.Type.e_check:
|
|
38
|
-
console.log('Field type: Check');
|
|
39
|
-
break;
|
|
40
|
-
case PDFNet.Field.Type.e_radio:
|
|
41
|
-
console.log('Field type: Radio');
|
|
42
|
-
break;
|
|
43
|
-
case PDFNet.Field.Type.e_text:
|
|
44
|
-
console.log('Field type: Text');
|
|
45
|
-
break;
|
|
46
|
-
case PDFNet.Field.Type.e_choice:
|
|
47
|
-
console.log('Field type: Choice');
|
|
48
|
-
break;
|
|
49
|
-
case PDFNet.Field.Type.e_signature:
|
|
50
|
-
console.log('Field type: Signature');
|
|
51
|
-
break;
|
|
52
|
-
default:
|
|
53
|
-
console.log('Field type: Null');
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
console.log('------------------------------')
|
|
57
|
-
}
|
|
58
|
-
console.log('Done.');
|
|
59
|
-
} catch (err) {
|
|
60
|
-
console.log(err);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Example 2) Import XFDF into FDF, then merge data from FDF into PDF
|
|
64
|
-
try {
|
|
65
|
-
// FDF to PDF
|
|
66
|
-
// form fields
|
|
67
|
-
console.log('Import form field data from XFDF to FDF.');
|
|
68
|
-
|
|
69
|
-
const fdf_doc1 = await PDFNet.FDFDoc.createFromXFDF(inputPath + 'form1_data.xfdf');
|
|
70
|
-
await fdf_doc1.save(outputPath + 'form1_data.fdf');
|
|
71
|
-
|
|
72
|
-
// annotations
|
|
73
|
-
console.log('Import annotations from XFDF to FDF.');
|
|
74
|
-
|
|
75
|
-
const fdf_doc2 = await PDFNet.FDFDoc.createFromXFDF(inputPath + 'form1_annots.xfdf');
|
|
76
|
-
await fdf_doc2.save(outputPath + 'form1_annots.fdf');
|
|
77
|
-
|
|
78
|
-
// FDF to PDF
|
|
79
|
-
// form fields
|
|
80
|
-
console.log('Merge form field data from FDF.');
|
|
81
|
-
|
|
82
|
-
const doc = await PDFNet.PDFDoc.createFromFilePath(`${inputPath}form1.pdf`);
|
|
83
|
-
doc.initSecurityHandler();
|
|
84
|
-
await doc.fdfMerge(fdf_doc1);
|
|
85
|
-
|
|
86
|
-
// Refreshing missing appearances is not required here, but is recommended to make them
|
|
87
|
-
// visible in PDF viewers with incomplete annotation viewing support. (such as Chrome)
|
|
88
|
-
doc.refreshAnnotAppearances();
|
|
89
|
-
|
|
90
|
-
await doc.save(outputPath + 'form1_filled.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
91
|
-
|
|
92
|
-
// annotations
|
|
93
|
-
console.log('Merge annotations from FDF.');
|
|
94
|
-
|
|
95
|
-
await doc.fdfMerge(fdf_doc2);
|
|
96
|
-
// Refreshing missing appearances is not required here, but is recommended to make them
|
|
97
|
-
// visible in PDF viewers with incomplete annotation viewing support. (such as Chrome)
|
|
98
|
-
doc.refreshAnnotAppearances();
|
|
99
|
-
await doc.save(outputPath + 'form1_filled_with_annots.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
100
|
-
console.log('Done.');
|
|
101
|
-
} catch (err) {
|
|
102
|
-
console.log(err);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// Example 3) Extract data from PDF to FDF, then export FDF as XFDF
|
|
107
|
-
try {
|
|
108
|
-
// PDF to FDF
|
|
109
|
-
const in_doc = await PDFNet.PDFDoc.createFromFilePath(outputPath + 'form1_filled_with_annots.pdf');
|
|
110
|
-
in_doc.initSecurityHandler();
|
|
111
|
-
|
|
112
|
-
// form fields only
|
|
113
|
-
console.log('Extract form fields data to FDF.');
|
|
114
|
-
|
|
115
|
-
const doc_fields = await in_doc.fdfExtract(PDFNet.PDFDoc.ExtractFlag.e_forms_only);
|
|
116
|
-
doc_fields.setPDFFileName('../form1_filled_with_annots.pdf');
|
|
117
|
-
await doc_fields.save(outputPath + 'form1_filled_data.fdf');
|
|
118
|
-
|
|
119
|
-
// annotations only
|
|
120
|
-
console.log('Extract annotations to FDF.');
|
|
121
|
-
|
|
122
|
-
const doc_annots = await in_doc.fdfExtract(PDFNet.PDFDoc.ExtractFlag.e_annots_only);
|
|
123
|
-
doc_annots.setPDFFileName('../form1_filled_with_annots.pdf');
|
|
124
|
-
await doc_annots.save(outputPath + 'form1_filled_annot.fdf');
|
|
125
|
-
|
|
126
|
-
// both form fields and annotations
|
|
127
|
-
console.log('Extract both form fields and annotations to FDF.');
|
|
128
|
-
|
|
129
|
-
const doc_both = await in_doc.fdfExtract(PDFNet.PDFDoc.ExtractFlag.e_both);
|
|
130
|
-
doc_both.setPDFFileName('../form1_filled_with_annots.pdf');
|
|
131
|
-
await doc_both.save(outputPath + 'form1_filled_both.fdf');
|
|
132
|
-
|
|
133
|
-
// FDF to XFDF
|
|
134
|
-
// form fields
|
|
135
|
-
console.log('Export form field data from FDF to XFDF.');
|
|
136
|
-
|
|
137
|
-
await doc_fields.saveAsXFDF(outputPath + 'form1_filled_data.xfdf');
|
|
138
|
-
|
|
139
|
-
// annotations
|
|
140
|
-
console.log('Export annotations from FDF to XFDF.');
|
|
141
|
-
|
|
142
|
-
await doc_annots.saveAsXFDF(outputPath + 'form1_filled_annot.xfdf');
|
|
143
|
-
|
|
144
|
-
// both form fields and annotations
|
|
145
|
-
console.log('Export both form fields and annotations from FDF to XFDF.');
|
|
146
|
-
|
|
147
|
-
await doc_both.saveAsXFDF(outputPath + 'form1_filled_both.xfdf');
|
|
148
|
-
|
|
149
|
-
console.log('Done.');
|
|
150
|
-
} catch (err) {
|
|
151
|
-
console.log(err);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Example 4) Merge/Extract XFDF into/from PDF
|
|
155
|
-
try {
|
|
156
|
-
// Merge XFDF from string
|
|
157
|
-
const in_doc = await PDFNet.PDFDoc.createFromFilePath(inputPath + 'numbered.pdf');
|
|
158
|
-
in_doc.initSecurityHandler();
|
|
159
|
-
|
|
160
|
-
console.log('Merge XFDF string into PDF.');
|
|
161
|
-
|
|
162
|
-
const str = `<?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="http://ns.adobe.com/xfdf" xml:space="preserve"><square subject="Rectangle" page="0" name="cf4d2e58-e9c5-2a58-5b4d-9b4b1a330e45" title="user" creationdate="D:20120827112326-07'00'" date="D:20120827112326-07'00'" rect="227.7814207650273,597.6174863387978,437.07103825136608,705.0491803278688" color="#000000" interior-color="#FFFF00" flags="print" width="1"><popup flags="print,nozoom,norotate" open="no" page="0" rect="0,792,0,792" /></square></xfdf>`;
|
|
163
|
-
|
|
164
|
-
const fdoc = await PDFNet.FDFDoc.createFromXFDF(str);
|
|
165
|
-
in_doc.fdfMerge(fdoc);
|
|
166
|
-
await in_doc.save(outputPath + 'numbered_modified.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
167
|
-
console.log('Merge complete.');
|
|
168
|
-
|
|
169
|
-
// Extract XFDF as string
|
|
170
|
-
console.log('Extract XFDF as a string.');
|
|
171
|
-
|
|
172
|
-
const fdoc_new = await in_doc.fdfExtract(PDFNet.PDFDoc.ExtractFlag.e_both);
|
|
173
|
-
const XFDF_str = await fdoc_new.saveAsXFDFAsString();
|
|
174
|
-
console.log('Extracted XFDF: ');
|
|
175
|
-
console.log(XFDF_str);
|
|
176
|
-
console.log('Extract complete.');
|
|
177
|
-
} catch (err) {
|
|
178
|
-
console.log(err);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Example 5) Read FDF files directly
|
|
182
|
-
try {
|
|
183
|
-
const doc = await PDFNet.FDFDoc.createFromFilePath(outputPath + 'form1_filled_data.fdf');
|
|
184
|
-
|
|
185
|
-
for (const itr = await doc.getFieldIteratorBegin(); await itr.hasNext(); itr.next()) {
|
|
186
|
-
const field = await itr.current();
|
|
187
|
-
console.log('Field name: ' + await field.getName());
|
|
188
|
-
console.log('Field partial name: ' + await field.getPartialName());
|
|
189
|
-
|
|
190
|
-
console.log('------------------------------');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
console.log('Done.');
|
|
194
|
-
} catch (err) {
|
|
195
|
-
console.log(err);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Example 6) Direct generation of FDF.
|
|
199
|
-
try
|
|
200
|
-
{
|
|
201
|
-
const doc = await PDFNet.FDFDoc.create();
|
|
202
|
-
// Create new fields (i.e. key/value pairs).
|
|
203
|
-
doc.fieldCreateFromString('Company', PDFNet.Field.Type.e_text, 'PDFTron Systems');
|
|
204
|
-
doc.fieldCreateFromString('First Name', PDFNet.Field.Type.e_text, 'John');
|
|
205
|
-
doc.fieldCreateFromString('Last Name', PDFNet.Field.Type.e_text, 'Doe');
|
|
206
|
-
|
|
207
|
-
await doc.save(outputPath + 'sample_output.fdf');
|
|
208
|
-
console.log('Done. Results saved in sample_output.fdf');
|
|
209
|
-
} catch (err) {
|
|
210
|
-
console.log(err);
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
|
|
215
|
-
};
|
|
216
|
-
exports.runFDFTest();
|
|
217
|
-
})(exports);
|
|
218
|
-
// eslint-disable-next-line spaced-comment
|
|
219
|
-
//# sourceURL=FDFTest.js
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-2022 by PDFTron Systems Inc. All Rights Reserved.
|
|
3
|
-
// Consult legal.txt regarding legal and license information.
|
|
4
|
-
//---------------------------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
//---------------------------------------------------------------------------------------
|
|
7
|
-
// 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://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
|
-
//# sourceURL=HTML2PDFTest.js
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-2022 by PDFTron Systems Inc. All Rights Reserved.
|
|
3
|
-
// Consult legal.txt regarding legal and license information.
|
|
4
|
-
//---------------------------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
8
|
-
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
9
|
-
|
|
10
|
-
// 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,130 +0,0 @@
|
|
|
1
|
-
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-2022 by PDFTron Systems Inc. All Rights Reserved.
|
|
3
|
-
// Consult legal.txt regarding legal and license information.
|
|
4
|
-
//---------------------------------------------------------------------------------------
|
|
5
|
-
|
|
6
|
-
//-----------------------------------------------------------------------------------
|
|
7
|
-
// 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('@pdftron/pdfnet-node');
|
|
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
|
-
//# sourceURL=ImageExtractTest.js
|