@pdftron/pdfnet-node-samples 12.2.0 → 12.2.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.
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// It supports several input formats like docx, xlsx, rtf, txt, html, pub, emf, etc. For more details, visit
|
|
9
9
|
// https://docs.apryse.com/documentation/windows/guides/features/conversion/convert-other/
|
|
10
10
|
//
|
|
11
|
-
//
|
|
11
|
+
// It is possible that a document will require the PDFNet printer for conversion.
|
|
12
12
|
// The installing application must be run as administrator. The manifest for this sample
|
|
13
13
|
// specifies appropriate the UAC elevation.
|
|
14
14
|
//
|
|
@@ -37,7 +37,6 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
|
37
37
|
|
|
38
38
|
const testfiles = [
|
|
39
39
|
new Testfile('simple-word_2007.docx', 'docx2pdf.pdf'),
|
|
40
|
-
new Testfile('simple-powerpoint_2007.pptx', 'pptx2pdf.pdf'),
|
|
41
40
|
new Testfile('simple-excel_2007.xlsx', 'xlsx2pdf.pdf'),
|
|
42
41
|
new Testfile('simple-publisher.pub', 'pub2pdf.pdf'),
|
|
43
42
|
new Testfile('simple-text.txt', 'txt2pdf.pdf'),
|
|
@@ -88,37 +87,60 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
|
|
|
88
87
|
};
|
|
89
88
|
|
|
90
89
|
const convertToPdfFromFile = async () => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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');
|
|
90
|
+
try {
|
|
91
|
+
if (await PDFNet.Convert.printerIsInstalled('PDFTron PDFNet')) {
|
|
92
|
+
await PDFNet.Convert.printerSetPrinterName('PDFTron PDFNet');
|
|
102
93
|
}
|
|
103
|
-
|
|
94
|
+
} catch (err) {
|
|
95
|
+
console.log('Warning: Unable to determine if the printer is installed or unable to set name of printer to use.');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const default_printer_mode = await PDFNet.Convert.printerGetMode();
|
|
99
|
+
|
|
104
100
|
for (const testfile of testfiles) {
|
|
105
101
|
|
|
106
102
|
try {
|
|
107
103
|
const pdfdoc = await PDFNet.PDFDoc.create();
|
|
104
|
+
|
|
105
|
+
await PDFNet.Convert.printerSetMode(default_printer_mode);
|
|
106
|
+
|
|
108
107
|
await pdfdoc.initSecurityHandler();
|
|
109
108
|
const inputFile = inputPath + testfile.inputFile;
|
|
110
109
|
const outputFile = outputPath + testfile.outputFile;
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
|
|
111
|
+
let retryConvert = false;
|
|
112
|
+
try {
|
|
113
|
+
await PDFNet.Convert.toPdf(pdfdoc, inputFile);
|
|
114
|
+
await pdfdoc.save(outputFile, PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
115
|
+
} catch (err) {
|
|
116
|
+
if (!(await PDFNet.Convert.printerIsInstalled())) {
|
|
117
|
+
try {
|
|
118
|
+
// This will fail if not run as administrator. Harmless if PDFNet
|
|
119
|
+
// printer already installed
|
|
120
|
+
console.log('Installing printer (requires Windows platform and administrator)');
|
|
121
|
+
await PDFNet.Convert.printerInstall();
|
|
122
|
+
await PDFNet.Convert.printerSetPrinterName('PDFTron PDFNet');
|
|
123
|
+
console.log('Installed printer ' + await PDFNet.Convert.printerGetPrinterName());
|
|
124
|
+
} catch (installErr) {
|
|
125
|
+
console.log('Unable to install printer');
|
|
126
|
+
throw err; // original exception
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
await PDFNet.Convert.printerSetMode(PDFNet.Convert.PrinterMode.e_printer_only);
|
|
130
|
+
retryConvert = true;
|
|
131
|
+
}
|
|
132
|
+
if (retryConvert) {
|
|
133
|
+
await PDFNet.Convert.toPdf(pdfdoc, inputFile);
|
|
134
|
+
await pdfdoc.save(outputFile, PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
113
135
|
}
|
|
114
|
-
await PDFNet.Convert.toPdf(pdfdoc, inputFile);
|
|
115
|
-
await pdfdoc.save(outputFile, PDFNet.SDFDoc.SaveOptions.e_linearized);
|
|
116
136
|
console.log('Converted file: ' + testfile.inputFile + '\nto: ' + testfile.outputFile);
|
|
117
137
|
} catch (err) {
|
|
118
138
|
console.log('Unable to convert file ' + testfile.inputFile);
|
|
119
139
|
console.log(err);
|
|
120
140
|
}
|
|
121
141
|
}
|
|
142
|
+
|
|
143
|
+
await PDFNet.Convert.printerSetMode(default_printer_mode);
|
|
122
144
|
};
|
|
123
145
|
|
|
124
146
|
const convertSpecificFormats = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdftron/pdfnet-node-samples",
|
|
3
|
-
"version": "12.2.
|
|
3
|
+
"version": "12.2.1",
|
|
4
4
|
"description": "Sample code for the @pdftron/pdfnet-node package.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "run-script-os",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"homepage": "https://www.apryse.com",
|
|
14
14
|
"repository": "https://github.com/XodoDocs/PDFTronCore.git",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@pdftron/pdfnet-node": "^12.2.
|
|
16
|
+
"@pdftron/pdfnet-node": "^12.2.1",
|
|
17
17
|
"run-script-os": "^1.1.6",
|
|
18
18
|
"underscore": "^1.13.6",
|
|
19
19
|
"xhr2": "^0.2.1"
|