@pdftron/pdfnet-node-samples 9.5.0-4 → 9.5.0-4-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 +2 -2
- package/{samples/AdvancedImagingTest → AdvancedImagingTest}/AdvancedImagingTest.js +5 -5
- package/{samples/AnnotationTest → AnnotationTest}/AnnotationTest.js +1 -1
- package/BarcodeTest/BarcodeTest.js +120 -0
- package/{samples/BookmarkTest → BookmarkTest}/BookmarkTest.js +1 -1
- package/{samples/CAD2PDFTest → CAD2PDFTest}/CAD2PDFTest.js +5 -5
- package/{samples/ContentReplacerTest → ContentReplacerTest}/ContentReplacerTest.js +1 -1
- package/ConvertPrintTest/ConvertPrintTest.js +153 -0
- package/{samples/ConvertTest → ConvertTest}/ConvertTest.js +12 -79
- package/{samples/DataExtractionTest → DataExtractionTest}/DataExtractionTest.js +141 -10
- package/{samples/DigitalSignaturesTest → DigitalSignaturesTest}/DigitalSignaturesTest.js +126 -12
- package/DocumentCreationTest/DocumentCreationTest.js +409 -0
- package/{samples/ElementBuilderTest → ElementBuilderTest}/ElementBuilderTest.js +1 -1
- package/{samples/ElementEditTest → ElementEditTest}/ElementEditTest.js +1 -1
- package/{samples/ElementReaderAdvTest → ElementReaderAdvTest}/ElementReaderAdvTest.js +1 -1
- package/{samples/ElementReaderTest → ElementReaderTest}/ElementReaderTest.js +1 -1
- package/{samples/EncTest → EncTest}/EncTest.js +1 -1
- package/{samples/FDFTest → FDFTest}/FDFTest.js +1 -1
- package/FindReplaceTest/FindReplaceTest.js +56 -0
- package/{samples/HTML2PDFTest → HTML2PDFTest}/HTML2PDFTest.js +34 -35
- package/{samples/HighlightsTest → HighlightsTest}/HighlightsTest.js +1 -1
- package/{samples/ImageExtractTest → ImageExtractTest}/ImageExtractTest.js +3 -3
- package/{samples/ImpositionTest → ImpositionTest}/ImpositionTest.js +1 -1
- package/{samples/InteractiveFormsTest → InteractiveFormsTest}/InteractiveFormsTest.js +1 -1
- package/{samples/JBIG2Test → JBIG2Test}/JBIG2Test.js +7 -7
- package/{samples/LicenseKey → LicenseKey}/LicenseKey.js +3 -3
- package/{samples/LogicalStructureTest → LogicalStructureTest}/LogicalStructureTest.js +1 -1
- package/{samples/OCRTest → OCRTest}/OCRTest.js +6 -5
- package/{samples/OfficeTemplateTest → OfficeTemplateTest}/OfficeTemplateTest.js +2 -2
- package/{samples/OfficeToPDFTest → OfficeToPDFTest}/OfficeToPDFTest.js +1 -1
- package/{samples/OptimizerTest → OptimizerTest}/OptimizerTest.js +1 -1
- package/{samples/PDF2HtmlTest → PDF2HtmlTest}/PDF2HtmlTest.js +6 -6
- package/{samples/PDF2OfficeTest → PDF2OfficeTest}/PDF2OfficeTest.js +6 -6
- package/{samples/PDFATest → PDFATest}/PDFATest.js +1 -1
- package/{samples/PDFDocMemoryTest → PDFDocMemoryTest}/PDFDocMemoryTest.js +1 -1
- package/{samples/PDFDrawTest → PDFDrawTest}/PDFDrawTest.js +1 -1
- package/{samples/PDFLayersTest → PDFLayersTest}/PDFLayersTest.js +1 -1
- package/{samples/PDFPackageTest → PDFPackageTest}/PDFPackageTest.js +1 -1
- package/{samples/PDFPageTest → PDFPageTest}/PDFPageTest.js +1 -1
- package/{samples/PDFRedactTest → PDFRedactTest}/PDFRedactTest.js +1 -1
- package/PDFUATest/PDFUATest.js +88 -0
- package/{samples/PageLabelsTest → PageLabelsTest}/PageLabelsTest.js +1 -1
- package/{samples/PatternTest → PatternTest}/PatternTest.js +1 -1
- package/{samples/RectTest → RectTest}/RectTest.js +1 -1
- package/{samples/SDFTest → SDFTest}/SDFTest.js +3 -4
- package/{samples/StamperTest → StamperTest}/StamperTest.js +1 -1
- package/TestFiles/BusinessCardTemplate.pdf +0 -0
- package/TestFiles/Email.pdf +0 -0
- package/TestFiles/Fishermen.docx +0 -0
- package/TestFiles/Font_licenses.txt +140 -0
- package/TestFiles/Invoice.pdf +0 -0
- package/TestFiles/License.txt +1 -0
- package/TestFiles/Misc-Fixed.pfa +1166 -0
- package/TestFiles/NotoSans_with_hindi.ttf +0 -0
- package/TestFiles/Output/empty +1 -0
- package/TestFiles/SHA-2 Root USERTrust RSA CA Sectigo timestamping.crt +34 -0
- package/TestFiles/SYH_Letter.docx +0 -0
- package/TestFiles/Scientific_Publication.pdf +0 -0
- package/TestFiles/TigerText.pdf +0 -0
- package/TestFiles/US061222892-a.pdf +0 -0
- package/TestFiles/apryse.bmp +0 -0
- package/TestFiles/apryse.cer +0 -0
- package/TestFiles/apryse.pfx +0 -0
- package/TestFiles/autotag_input.pdf +0 -0
- package/TestFiles/butterfly.png +0 -0
- package/TestFiles/credit card numbers.pdf +0 -0
- package/TestFiles/dice.jpg +0 -0
- package/TestFiles/dice.u3d +0 -0
- package/TestFiles/doc_to_sign.pdf +0 -0
- package/TestFiles/factsheet_Arabic.docx +0 -0
- package/TestFiles/financial.pdf +0 -0
- package/TestFiles/find-replace-test.pdf +0 -0
- package/TestFiles/find-replace-test_(en_to_fr).xlf +88 -0
- package/TestFiles/fish.pdf +0 -0
- package/TestFiles/font.ttf +0 -0
- package/TestFiles/form1.pdf +246 -0
- package/TestFiles/form1_annots.xfdf +34 -0
- package/TestFiles/form1_data.fdf +4 -0
- package/TestFiles/form1_data.xfdf +140 -0
- package/TestFiles/formfields-scanned-withfields.pdf +0 -0
- package/TestFiles/formfields-scanned.pdf +0 -0
- package/TestFiles/formfields.pdf +0 -0
- package/TestFiles/grayscale.tif +0 -0
- package/TestFiles/hindi_sample_utf16le.txt +0 -0
- package/TestFiles/imagemask.dat +32 -0
- package/TestFiles/logo_red.png +0 -0
- package/TestFiles/lorem_ipsum.pdf +0 -0
- package/TestFiles/multipage.tif +0 -0
- package/TestFiles/my_stream.txt +2310 -0
- package/TestFiles/newsletter.pdf +0 -0
- package/TestFiles/newsletter.xod +0 -0
- package/TestFiles/numbered.pdf +0 -0
- package/TestFiles/op_blend_test.pdf +1497 -1
- package/TestFiles/palm.jp2 +0 -0
- package/TestFiles/paragraphs_and_tables.pdf +0 -0
- package/TestFiles/pdfnet.gif +0 -0
- package/TestFiles/pdftron_smart_substitution.plugin +0 -0
- package/TestFiles/peppers.jpg +0 -0
- package/TestFiles/signature.jpg +0 -0
- package/TestFiles/simple-emf.emf +0 -0
- package/TestFiles/simple-excel_2007.xlsx +0 -0
- package/TestFiles/simple-outlook.msg +0 -0
- package/TestFiles/simple-powerpoint_2007.pptx +0 -0
- package/TestFiles/simple-publisher.pub +0 -0
- package/TestFiles/simple-rtf.rtf +224 -0
- package/TestFiles/simple-text.txt +61 -0
- package/TestFiles/simple-visio.vsd +0 -0
- package/TestFiles/simple-webpage.html +731 -0
- package/TestFiles/simple-webpage.mht +6972 -0
- package/TestFiles/simple-webpage_files/colorschememapping.xml +2 -0
- package/TestFiles/simple-webpage_files/filelist.xml +14 -0
- package/TestFiles/simple-webpage_files/image001.gif +0 -0
- package/TestFiles/simple-webpage_files/image002.png +0 -0
- package/TestFiles/simple-webpage_files/image003.jpg +0 -0
- package/TestFiles/simple-webpage_files/image004.emz +0 -0
- package/TestFiles/simple-webpage_files/image005.gif +0 -0
- package/TestFiles/simple-webpage_files/image006.png +0 -0
- package/TestFiles/simple-webpage_files/image007.gif +0 -0
- package/TestFiles/simple-webpage_files/oledata.mso +0 -0
- package/TestFiles/simple-webpage_files/themedata.thmx +0 -0
- package/TestFiles/simple-word_2007.docx +0 -0
- package/TestFiles/simple-xps.xps +0 -0
- package/TestFiles/table.pdf +0 -0
- package/TestFiles/tagged.pdf +0 -0
- package/TestFiles/the_rime_of_the_ancient_mariner.docx +0 -0
- package/TestFiles/tiger.pdf +0 -0
- package/TestFiles/tiger.svg +378 -0
- package/TestFiles/waiver.pdf +0 -0
- package/TestFiles/waiver_withApprovalField.pdf +0 -0
- package/TestFiles/waiver_withApprovalField_certified.pdf +421 -1
- package/TestFiles/waiver_withApprovalField_certified_approved.pdf +465 -1
- package/{samples/TextExtractTest → TextExtractTest}/TextExtractTest.js +1 -1
- package/{samples/TextSearchTest → TextSearchTest}/TextSearchTest.js +2 -2
- package/TransPDFTest/TransPDFTest.js +68 -0
- package/{samples/U3DTest → U3DTest}/U3DTest.js +1 -1
- package/{samples/UndoRedoTest → UndoRedoTest}/UndoRedoTest.js +1 -1
- package/{samples/UnicodeWriteTest → UnicodeWriteTest}/UnicodeWriteTest.js +1 -1
- package/{samples/WebViewerConvertTest → WebViewerConvertTest}/WebViewerConvertTest.js +2 -2
- package/legal.txt +632 -0
- package/license.pdf +0 -0
- package/package.json +14 -41
- package/readme.md +32 -7
- package/{samples/runall.bat → runall.bat} +12 -12
- package/scripts/install.js +68 -0
- /package/{samples/runall.sh → runall.sh} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
2
|
+
// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
|
|
3
3
|
// Consult legal.txt regarding legal and license information.
|
|
4
4
|
//---------------------------------------------------------------------------------------
|
|
5
5
|
|
|
@@ -113,4 +113,4 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
|
113
113
|
exports.runAddImageTest();
|
|
114
114
|
})(exports);
|
|
115
115
|
// eslint-disable-next-line spaced-comment
|
|
116
|
-
//# sourceURL=AddImageTest.js
|
|
116
|
+
//# sourceURL=AddImageTest.js
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
2
|
+
// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
|
|
3
3
|
// Consult legal.txt regarding legal and license information.
|
|
4
4
|
//---------------------------------------------------------------------------------------
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// The AdvancedImaging module is an optional PDFNet Add-on that can be used to convert AdvancedImaging
|
|
10
10
|
// documents into PDF documents
|
|
11
11
|
//
|
|
12
|
-
// The
|
|
12
|
+
// The Apryse SDK AdvancedImaging module can be downloaded from http://www.apryse.com/
|
|
13
13
|
//---------------------------------------------------------------------------------------
|
|
14
14
|
|
|
15
15
|
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
@@ -23,13 +23,13 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
|
23
23
|
const main = async () => {
|
|
24
24
|
|
|
25
25
|
try {
|
|
26
|
-
await PDFNet.addResourceSearchPath('
|
|
26
|
+
await PDFNet.addResourceSearchPath('../../lib/');
|
|
27
27
|
|
|
28
28
|
if (!await PDFNet.AdvancedImagingModule.isModuleAvailable()) {
|
|
29
|
-
console.log('\nUnable to run AdvancedImagingTest:
|
|
29
|
+
console.log('\nUnable to run AdvancedImagingTest: Apryse SDK AdvancedImaging module not available.');
|
|
30
30
|
console.log('---------------------------------------------------------------');
|
|
31
31
|
console.log('The AdvancedImaging module is an optional add-on, available for download');
|
|
32
|
-
console.log('at http://www.
|
|
32
|
+
console.log('at http://www.apryse.com/. If you have already downloaded this');
|
|
33
33
|
console.log('module, ensure that the SDK is able to find the required files');
|
|
34
34
|
console.log('using the PDFNet::AddResourceSearchPath() function.\n');
|
|
35
35
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
2
|
+
// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
|
|
3
3
|
// Consult legal.txt regarding legal and license information.
|
|
4
4
|
//---------------------------------------------------------------------------------------
|
|
5
5
|
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
//---------------------------------------------------------------------------------------
|
|
2
|
+
// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
|
|
3
|
+
// Consult legal.txt regarding legal and license information.
|
|
4
|
+
//---------------------------------------------------------------------------------------
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
9
|
+
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
10
|
+
|
|
11
|
+
((exports) => {
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
//---------------------------------------------------------------------------------------
|
|
15
|
+
// The Barcode Module is an optional PDFNet add-on that can be used to extract
|
|
16
|
+
// various types of barcodes from PDF documents.
|
|
17
|
+
//
|
|
18
|
+
// The Apryse SDK Barcode Module can be downloaded from https://dev.apryse.com/
|
|
19
|
+
//---------------------------------------------------------------------------------------
|
|
20
|
+
exports.runBarcodeTest = () => {
|
|
21
|
+
const main = async () => {
|
|
22
|
+
|
|
23
|
+
PDFNet.addResourceSearchPath('../../lib/');
|
|
24
|
+
|
|
25
|
+
if (!(await PDFNet.BarcodeModule.isModuleAvailable())) {
|
|
26
|
+
console.log('\nUnable to run BarcodeTest: Apryse SDK Barcode Module not available.');
|
|
27
|
+
console.log('---------------------------------------------------------------');
|
|
28
|
+
console.log('The Barcode Module is an optional add-on, available for download');
|
|
29
|
+
console.log('at https://dev.apryse.com/. If you have already downloaded this');
|
|
30
|
+
console.log('module, ensure that the SDK is able to find the required files');
|
|
31
|
+
console.log('using the PDFNet.addResourceSearchPath() function.\n');
|
|
32
|
+
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Relative path to the folder containing test files.
|
|
37
|
+
const input_path = '../TestFiles/Barcode/';
|
|
38
|
+
const output_path = '../TestFiles/Output/';
|
|
39
|
+
|
|
40
|
+
//--------------------------------------------------------------------------------
|
|
41
|
+
// Example 1) Detect and extract all barcodes from a PDF document into a JSON file
|
|
42
|
+
try {
|
|
43
|
+
|
|
44
|
+
console.log('Example 1: extracting barcodes from barcodes.pdf to barcodes.json');
|
|
45
|
+
|
|
46
|
+
// A) Open the .pdf document
|
|
47
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'barcodes.pdf');
|
|
48
|
+
|
|
49
|
+
// B) Detect PDF barcodes with the default options
|
|
50
|
+
await PDFNet.BarcodeModule.extractBarcodes(doc, output_path + 'barcodes.json');
|
|
51
|
+
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.log(err);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//--------------------------------------------------------------------------------
|
|
57
|
+
// Example 2) Limit barcode extraction to a range of pages, and retrieve the JSON into a
|
|
58
|
+
// local string variable, which is then written to a file in a separate function call
|
|
59
|
+
try {
|
|
60
|
+
|
|
61
|
+
console.log('Example 2: extracting barcodes from pages 1-2 to barcodes_from_pages_1-2.json');
|
|
62
|
+
|
|
63
|
+
// A) Open the .pdf document
|
|
64
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'barcodes.pdf');
|
|
65
|
+
|
|
66
|
+
// B) Detect PDF barcodes with custom options
|
|
67
|
+
const options = new PDFNet.BarcodeModule.BarcodeOptions();
|
|
68
|
+
|
|
69
|
+
// Convert only the first two pages
|
|
70
|
+
options.setPages('1-2');
|
|
71
|
+
|
|
72
|
+
const json = await PDFNet.BarcodeModule.extractBarcodesAsString(doc, options);
|
|
73
|
+
|
|
74
|
+
// C) Save JSON to file
|
|
75
|
+
fs.writeFileSync(output_path + 'barcodes_from_pages_1-2.json', json);
|
|
76
|
+
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.log(err);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//--------------------------------------------------------------------------------
|
|
82
|
+
// Example 3) Narrow down barcode types and allow the detection of both horizontal
|
|
83
|
+
// and vertical barcodes
|
|
84
|
+
try {
|
|
85
|
+
|
|
86
|
+
console.log('Example 3: extracting basic horizontal and vertical barcodes');
|
|
87
|
+
|
|
88
|
+
// A) Open the .pdf document
|
|
89
|
+
const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'barcodes.pdf');
|
|
90
|
+
|
|
91
|
+
// B) Detect only basic 1D barcodes, both horizontal and vertical
|
|
92
|
+
const options = new PDFNet.BarcodeModule.BarcodeOptions();
|
|
93
|
+
|
|
94
|
+
// Limit extraction to basic 1D barcode types, such as EAN 13, EAN 8, UPCA, UPCE,
|
|
95
|
+
// Code 3 of 9, Code 128, Code 2 of 5, Code 93, Code 11 and GS1 Databar.
|
|
96
|
+
options.setBarcodeSearchTypes(PDFNet.BarcodeModule.BarcodeOptions.BarcodeTypeGroup.e_linear);
|
|
97
|
+
|
|
98
|
+
// Search for barcodes oriented horizontally and vertically
|
|
99
|
+
options.setBarcodeOrientations(
|
|
100
|
+
PDFNet.BarcodeModule.BarcodeOptions.BarcodeOrientation.e_horizontal |
|
|
101
|
+
PDFNet.BarcodeModule.BarcodeOptions.BarcodeOrientation.e_vertical);
|
|
102
|
+
|
|
103
|
+
await PDFNet.BarcodeModule.extractBarcodes(doc, output_path + 'barcodes_1D.json', options);
|
|
104
|
+
|
|
105
|
+
} catch (err) {
|
|
106
|
+
console.log(err);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//////////////////////////////////////////////////////////////////////////
|
|
110
|
+
|
|
111
|
+
console.log('Done.');
|
|
112
|
+
};
|
|
113
|
+
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
|
|
114
|
+
console.log('Error: ' + JSON.stringify(error));
|
|
115
|
+
}).then(function(){ return PDFNet.shutdown(); });
|
|
116
|
+
};
|
|
117
|
+
exports.runBarcodeTest();
|
|
118
|
+
})(exports);
|
|
119
|
+
// eslint-disable-next-line spaced-comment
|
|
120
|
+
//# sourceURL=BarcodeTest.js
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
2
|
+
// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
|
|
3
3
|
// Consult legal.txt regarding legal and license information.
|
|
4
4
|
//---------------------------------------------------------------------------------------
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
2
|
+
// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
|
|
3
3
|
// Consult legal.txt regarding legal and license information.
|
|
4
4
|
//---------------------------------------------------------------------------------------
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// The CAD module is an optional PDFNet Add-on that can be used to convert CAD
|
|
11
11
|
// documents into PDF documents
|
|
12
12
|
//
|
|
13
|
-
// The
|
|
13
|
+
// The Apryse SDK CAD module can be downloaded from http://www.apryse.com/
|
|
14
14
|
//---------------------------------------------------------------------------------------
|
|
15
15
|
|
|
16
16
|
|
|
@@ -33,12 +33,12 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
|
33
33
|
|
|
34
34
|
const main = async () => {
|
|
35
35
|
try {
|
|
36
|
-
await PDFNet.addResourceSearchPath('
|
|
36
|
+
await PDFNet.addResourceSearchPath('../../lib/');
|
|
37
37
|
if (!(await PDFNet.CADModule.isModuleAvailable())) {
|
|
38
|
-
console.log('\nUnable to run CAD2PDFTest:
|
|
38
|
+
console.log('\nUnable to run CAD2PDFTest: Apryse SDK CAD module not available.');
|
|
39
39
|
console.log('---------------------------------------------------------------');
|
|
40
40
|
console.log('The CAD module is an optional add-on, available for download');
|
|
41
|
-
console.log('at http://www.
|
|
41
|
+
console.log('at http://www.apryse.com/. If you have already downloaded this');
|
|
42
42
|
console.log('module, ensure that the SDK is able to find the required files');
|
|
43
43
|
console.log('using the PDFNet.addResourceSearchPath() function.\n');
|
|
44
44
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
2
|
+
// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
|
|
3
3
|
// Consult legal.txt regarding legal and license information.
|
|
4
4
|
//---------------------------------------------------------------------------------------
|
|
5
5
|
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
//---------------------------------------------------------------------------------------
|
|
2
|
+
// Copyright (c) 2001-2021 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 to PDF with virtual printer on Windows.
|
|
8
|
+
// It supports several input formats like docx, xlsx, rtf, txt, html, pub, emf, etc. For more details, visit
|
|
9
|
+
// https://docs.apryse.com/documentation/windows/guides/features/conversion/convert-other/
|
|
10
|
+
//
|
|
11
|
+
// To check if ToPDF (or ToXPS) require that PDFNet printer is installed use Convert::RequiresPrinter(filename).
|
|
12
|
+
// The installing application must be run as administrator. The manifest for this sample
|
|
13
|
+
// specifies appropriate the UAC elevation.
|
|
14
|
+
//
|
|
15
|
+
// Note: the PDFNet printer is a virtual XPS printer supported on Vista SP1 and Windows 7.
|
|
16
|
+
// For Windows XP SP2 or higher, or Vista SP0 you need to install the XPS Essentials Pack (or
|
|
17
|
+
// equivalent redistributables). You can download the XPS Essentials Pack from:
|
|
18
|
+
// http://www.microsoft.com/downloads/details.aspx?FamilyId=B8DCFFDD-E3A5-44CC-8021-7649FD37FFEE&displaylang=en
|
|
19
|
+
// Windows XP Sp2 will also need the Microsoft Core XML Services (MSXML) 6.0:
|
|
20
|
+
// http://www.microsoft.com/downloads/details.aspx?familyid=993C0BCF-3BCF-4009-BE21-27E85E1857B1&displaylang=en
|
|
21
|
+
//
|
|
22
|
+
// Note: Convert.fromEmf and Convert.toEmf will only work on Windows and require GDI+.
|
|
23
|
+
//
|
|
24
|
+
// Please contact us if you have any questions.
|
|
25
|
+
//---------------------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
const { PDFNet } = require('@pdftron/pdfnet-node');
|
|
28
|
+
const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
29
|
+
|
|
30
|
+
((exports) => {
|
|
31
|
+
'use strict';
|
|
32
|
+
|
|
33
|
+
let Testfile = function (inputFile, outputFile) {
|
|
34
|
+
this.inputFile = inputFile;
|
|
35
|
+
this.outputFile = outputFile;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const testfiles = [
|
|
39
|
+
new Testfile('simple-word_2007.docx', 'docx2pdf.pdf'),
|
|
40
|
+
new Testfile('simple-powerpoint_2007.pptx', 'pptx2pdf.pdf'),
|
|
41
|
+
new Testfile('simple-excel_2007.xlsx', 'xlsx2pdf.pdf'),
|
|
42
|
+
new Testfile('simple-publisher.pub', 'pub2pdf.pdf'),
|
|
43
|
+
new Testfile('simple-text.txt', 'txt2pdf.pdf'),
|
|
44
|
+
new Testfile('simple-rtf.rtf', 'rtf2pdf.pdf'),
|
|
45
|
+
new Testfile('simple-emf.emf', 'emf2pdf.pdf'),
|
|
46
|
+
new Testfile('simple-webpage.mht','mht2pdf.pdf'),
|
|
47
|
+
new Testfile('simple-webpage.html', 'html2pdf.pdf'),
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
const inputPath = '../TestFiles/';
|
|
53
|
+
const outputPath = '../TestFiles/Output/';
|
|
54
|
+
|
|
55
|
+
exports.runConvertPrintTest = () => {
|
|
56
|
+
|
|
57
|
+
const main = async () => {
|
|
58
|
+
if (process.platform === 'win32') {
|
|
59
|
+
try {
|
|
60
|
+
await convertToPdfFromFile();
|
|
61
|
+
console.log('ConvertFile succeeded');
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.log('ConvertFile failed');
|
|
64
|
+
console.log(err);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
await convertSpecificFormats();
|
|
69
|
+
console.log('ConvertSpecificFormats succeeded');
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.log('ConvertSpecificFormats failed');
|
|
72
|
+
console.log(err);
|
|
73
|
+
}
|
|
74
|
+
if (await PDFNet.Convert.printerIsInstalled()) {
|
|
75
|
+
try {
|
|
76
|
+
console.log('Uninstalling printer (requires Windows platform and administrator)');
|
|
77
|
+
await PDFNet.Convert.printerUninstall();
|
|
78
|
+
console.log('Uninstalled printer ' + await PDFNet.Convert.printerGetPrinterName());
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.log('Unable to uninstall printer');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
console.log('Done.');
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.log('ConvertPrintTest only available on Windows');
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const convertToPdfFromFile = async () => {
|
|
91
|
+
if (await PDFNet.Convert.printerIsInstalled('PDFTron PDFNet')) {
|
|
92
|
+
await PDFNet.Convert.printerSetPrinterName('PDFTron PDFNet');
|
|
93
|
+
} else if (!(await PDFNet.Convert.printerIsInstalled())) {
|
|
94
|
+
try {
|
|
95
|
+
// This will fail if not run as administrator. Harmless if PDFNet
|
|
96
|
+
// printer already installed
|
|
97
|
+
console.log('Installing printer (requires Windows platform and administrator)');
|
|
98
|
+
await PDFNet.Convert.printerInstall();
|
|
99
|
+
console.log('Installed printer ' + await PDFNet.Convert.printerGetPrinterName());
|
|
100
|
+
} catch (err) {
|
|
101
|
+
console.log('Unable to install printer');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
for (const testfile of testfiles) {
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const pdfdoc = await PDFNet.PDFDoc.create();
|
|
108
|
+
await pdfdoc.initSecurityHandler();
|
|
109
|
+
const inputFile = inputPath + testfile.inputFile;
|
|
110
|
+
const outputFile = outputPath + testfile.outputFile;
|
|
111
|
+
if (await PDFNet.Convert.requiresPrinter(inputFile)) {
|
|
112
|
+
console.log('Using PDFNet printer to convert file ' + testfile.inputFile);
|
|
113
|
+
}
|
|
114
|
+
await PDFNet.Convert.toPdf(pdfdoc, inputFile);
|
|
115
|
+
await pdfdoc.save(outputFile, PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
116
|
+
console.log('Converted file: ' + testfile.inputFile + '\nto: ' + testfile.outputFile);
|
|
117
|
+
} catch (err) {
|
|
118
|
+
console.log('Unable to convert file ' + testfile.inputFile);
|
|
119
|
+
console.log(err);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const convertSpecificFormats = async () => {
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
// Convert MSWord document to XPS
|
|
128
|
+
console.log('Converting DOCX to XPS');
|
|
129
|
+
await PDFNet.Convert.fileToXps(inputPath + 'simple-word_2007.docx', outputPath + 'simple-word_2007.xps');
|
|
130
|
+
console.log('Saved simple-word_2007.xps');
|
|
131
|
+
} catch (err) {
|
|
132
|
+
console.log(err);
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const pdfdoc = await PDFNet.PDFDoc.create();
|
|
136
|
+
await pdfdoc.initSecurityHandler();
|
|
137
|
+
|
|
138
|
+
console.log('Converting from EMF');
|
|
139
|
+
await PDFNet.Convert.fromEmf(pdfdoc, inputPath + 'simple-emf.emf');
|
|
140
|
+
await pdfdoc.save(outputPath + 'emf2pdf v2.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
141
|
+
console.log('Saved emf2pdf v2.pdf');
|
|
142
|
+
} catch (err) {
|
|
143
|
+
console.log(err);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
|
|
147
|
+
console.log('Error: ' + JSON.stringify(error));
|
|
148
|
+
}).then(function(){ return PDFNet.shutdown(); });
|
|
149
|
+
};
|
|
150
|
+
exports.runConvertPrintTest();
|
|
151
|
+
})(exports);
|
|
152
|
+
// eslint-disable-next-line spaced-comment
|
|
153
|
+
//# sourceURL=ConvertPrintTest.js
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
//---------------------------------------------------------------------------------------
|
|
2
|
-
// Copyright (c) 2001-
|
|
2
|
+
// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
|
|
3
3
|
// Consult legal.txt regarding legal and license information.
|
|
4
4
|
//---------------------------------------------------------------------------------------
|
|
5
5
|
|
|
6
6
|
//---------------------------------------------------------------------------------------
|
|
7
7
|
// The following sample illustrates how to use the PDF::Convert utility class to convert
|
|
8
|
-
// documents and files to PDF, XPS, SVG, or EMF.
|
|
8
|
+
// documents and files to PDF, XPS, or SVG, or EMF. The sample also shows how to convert MS Office files
|
|
9
|
+
// using our built in conversion.
|
|
9
10
|
//
|
|
10
11
|
// Certain file formats such as XPS, EMF, PDF, and raster image formats can be directly
|
|
11
|
-
// converted to PDF or XPS.
|
|
12
|
-
// if ToPDF (or ToXPS) require that PDFNet printer is installed use Convert::RequiresPrinter(filename).
|
|
13
|
-
// The installing application must be run as administrator. The manifest for this sample
|
|
14
|
-
// specifies appropriate the UAC elevation.
|
|
15
|
-
//
|
|
16
|
-
// Note: the PDFNet printer is a virtual XPS printer supported on Vista SP1 and Windows 7.
|
|
17
|
-
// For Windows XP SP2 or higher, or Vista SP0 you need to install the XPS Essentials Pack (or
|
|
18
|
-
// equivalent redistributables). You can download the XPS Essentials Pack from:
|
|
19
|
-
// http://www.microsoft.com/downloads/details.aspx?FamilyId=B8DCFFDD-E3A5-44CC-8021-7649FD37FFEE&displaylang=en
|
|
20
|
-
// Windows XP Sp2 will also need the Microsoft Core XML Services (MSXML) 6.0:
|
|
21
|
-
// http://www.microsoft.com/downloads/details.aspx?familyid=993C0BCF-3BCF-4009-BE21-27E85E1857B1&displaylang=en
|
|
22
|
-
//
|
|
23
|
-
// Note: Convert.FromEmf and Convert.ToEmf will only work on Windows and require GDI+.
|
|
12
|
+
// converted to PDF or XPS.
|
|
24
13
|
//
|
|
25
14
|
// Please contact us if you have any questions.
|
|
26
15
|
//---------------------------------------------------------------------------------------
|
|
@@ -31,23 +20,18 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
|
31
20
|
((exports) => {
|
|
32
21
|
'use strict';
|
|
33
22
|
|
|
34
|
-
let Testfile = function (inputFile, outputFile
|
|
23
|
+
let Testfile = function (inputFile, outputFile) {
|
|
35
24
|
this.inputFile = inputFile;
|
|
36
25
|
this.outputFile = outputFile;
|
|
37
|
-
this.requiresWindowsPlatform = requiresWindowsPlatform;
|
|
38
26
|
}
|
|
39
27
|
|
|
40
28
|
const testfiles = [
|
|
41
|
-
new Testfile('simple-word_2007.docx', 'docx2pdf.pdf'
|
|
42
|
-
new Testfile('simple-powerpoint_2007.pptx', 'pptx2pdf.pdf'
|
|
43
|
-
new Testfile('simple-excel_2007.xlsx', 'xlsx2pdf.pdf'
|
|
44
|
-
new Testfile('simple-
|
|
45
|
-
new Testfile('
|
|
46
|
-
new Testfile('simple-
|
|
47
|
-
new Testfile('butterfly.png', 'png2pdf.pdf', false),
|
|
48
|
-
new Testfile('simple-emf.emf', 'emf2pdf.pdf', true),
|
|
49
|
-
new Testfile('simple-xps.xps', 'xps2pdf.pdf', false),
|
|
50
|
-
new Testfile('simple-webpage.html', 'html2pdf.pdf', true),
|
|
29
|
+
new Testfile('simple-word_2007.docx', 'docx2pdf.pdf'),
|
|
30
|
+
new Testfile('simple-powerpoint_2007.pptx', 'pptx2pdf.pdf'),
|
|
31
|
+
new Testfile('simple-excel_2007.xlsx', 'xlsx2pdf.pdf'),
|
|
32
|
+
new Testfile('simple-text.txt', 'txt2pdf.pdf'),
|
|
33
|
+
new Testfile('butterfly.png', 'png2pdf.pdf'),
|
|
34
|
+
new Testfile('simple-xps.xps', 'xps2pdf.pdf'),
|
|
51
35
|
]
|
|
52
36
|
|
|
53
37
|
const inputPath = '../TestFiles/';
|
|
@@ -72,47 +56,19 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
|
72
56
|
console.log(err);
|
|
73
57
|
}
|
|
74
58
|
|
|
75
|
-
if (process.platform === 'win32' && await PDFNet.Convert.printerIsInstalled()) {
|
|
76
|
-
try {
|
|
77
|
-
console.log('Uninstalling printer (requires Windows platform and administrator)');
|
|
78
|
-
await PDFNet.Convert.printerUninstall();
|
|
79
|
-
console.log('Uninstalled printer ' + await PDFNet.Convert.printerGetPrinterName());
|
|
80
|
-
} catch (err) {
|
|
81
|
-
console.log('Unable to uninstall printer');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
59
|
console.log('Done.');
|
|
86
60
|
};
|
|
87
61
|
|
|
88
62
|
const convertToPdfFromFile = async () => {
|
|
89
|
-
if (process.platform === 'win32') {
|
|
90
|
-
if (await PDFNet.Convert.printerIsInstalled('PDFTron PDFNet')) {
|
|
91
|
-
await PDFNet.Convert.printerSetPrinterName('PDFTron PDFNet');
|
|
92
|
-
} else if (!(await PDFNet.Convert.printerIsInstalled())) {
|
|
93
|
-
try {
|
|
94
|
-
// This will fail if not run as administrator. Harmless if PDFNet
|
|
95
|
-
// printer already installed
|
|
96
|
-
console.log('Installing printer (requires Windows platform and administrator)');
|
|
97
|
-
await PDFNet.Convert.printerInstall();
|
|
98
|
-
console.log('Installed printer ' + await PDFNet.Convert.printerGetPrinterName());
|
|
99
|
-
} catch (err) {
|
|
100
|
-
console.log('Unable to install printer');
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
63
|
|
|
105
64
|
for (const testfile of testfiles) {
|
|
106
|
-
if (process.platform !== 'win32' && testfile.requiresWindowsPlatform) continue;
|
|
107
65
|
|
|
108
66
|
try {
|
|
109
67
|
const pdfdoc = await PDFNet.PDFDoc.create();
|
|
110
68
|
await pdfdoc.initSecurityHandler();
|
|
111
69
|
const inputFile = inputPath + testfile.inputFile;
|
|
112
70
|
const outputFile = outputPath + testfile.outputFile;
|
|
113
|
-
|
|
114
|
-
console.log('Using PDFNet printer to convert file ' + testfile.inputFile);
|
|
115
|
-
}
|
|
71
|
+
await PDFNet.Convert.printerSetMode(PDFNet.Convert.PrinterMode.e_prefer_builtin_converter);
|
|
116
72
|
await PDFNet.Convert.toPdf(pdfdoc, inputFile);
|
|
117
73
|
await pdfdoc.save(outputFile, PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
118
74
|
console.log('Converted file: ' + testfile.inputFile + '\nto: ' + testfile.outputFile);
|
|
@@ -136,19 +92,6 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
|
136
92
|
console.log(err);
|
|
137
93
|
}
|
|
138
94
|
|
|
139
|
-
if (process.platform === 'win32') {
|
|
140
|
-
try {
|
|
141
|
-
const pdfdoc = await PDFNet.PDFDoc.create();
|
|
142
|
-
await pdfdoc.initSecurityHandler();
|
|
143
|
-
|
|
144
|
-
console.log('Converting from EMF');
|
|
145
|
-
await PDFNet.Convert.fromEmf(pdfdoc, inputPath + 'simple-emf.emf');
|
|
146
|
-
await pdfdoc.save(outputPath + 'emf2pdf v2.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
147
|
-
console.log('Saved emf2pdf v2.pdf');
|
|
148
|
-
} catch (err) {
|
|
149
|
-
console.log(err);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
95
|
|
|
153
96
|
try {
|
|
154
97
|
const pdfdoc = await PDFNet.PDFDoc.create();
|
|
@@ -194,16 +137,6 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
|
194
137
|
console.log(err);
|
|
195
138
|
}
|
|
196
139
|
|
|
197
|
-
if (process.platform === 'win32') {
|
|
198
|
-
try {
|
|
199
|
-
// Convert MSWord document to XPS
|
|
200
|
-
console.log('Converting DOCX to XPS');
|
|
201
|
-
await PDFNet.Convert.fileToXps(inputPath + 'simple-word_2007.docx', outputPath + 'simple-word_2007.xps');
|
|
202
|
-
console.log('Saved simple-word_2007.xps');
|
|
203
|
-
} catch (err) {
|
|
204
|
-
console.log(err);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
140
|
|
|
208
141
|
try {
|
|
209
142
|
// Convert PDF document to XPS
|