node-poppler 6.2.6 → 7.0.0
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/README.md +31 -13
- package/package.json +4 -2
- package/src/index.js +343 -305
- package/types/index.d.ts +520 -276
package/src/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const { execFile, spawn } = require("node:child_process");
|
|
4
|
+
const { promisify } = require("node:util");
|
|
3
5
|
const camelCase = require("camelcase");
|
|
4
|
-
const
|
|
5
|
-
const {
|
|
6
|
-
const { promisify } = require("util");
|
|
6
|
+
const { lt } = require("semver");
|
|
7
|
+
const { joinSafe, normalizeTrim } = require("upath");
|
|
7
8
|
|
|
8
9
|
const execFileAsync = promisify(execFile);
|
|
9
10
|
|
|
@@ -15,6 +16,7 @@ const errorMessages = {
|
|
|
15
16
|
4: "Error related to ICC profile",
|
|
16
17
|
99: "Other error",
|
|
17
18
|
3221226505: "Internal process error",
|
|
19
|
+
unk: "Unknown error",
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -22,24 +24,28 @@ const errorMessages = {
|
|
|
22
24
|
* @description Checks each option provided is valid, of the correct type, and can be used by specified
|
|
23
25
|
* version of binary.
|
|
24
26
|
* @ignore
|
|
25
|
-
* @param {object} acceptedOptions - Object containing options
|
|
27
|
+
* @param {object} acceptedOptions - Object containing accepted options.
|
|
26
28
|
* @param {object} options - Object containing options to pass to binary.
|
|
27
|
-
* @param {string
|
|
28
|
-
* @returns {
|
|
29
|
+
* @param {string} [version] - Version of binary.
|
|
30
|
+
* @returns {string[]} Array of CLI arguments.
|
|
29
31
|
* @throws If invalid arguments provided.
|
|
30
32
|
*/
|
|
31
33
|
function parseOptions(acceptedOptions, options, version) {
|
|
34
|
+
/** @type {string[]} */
|
|
32
35
|
const args = [];
|
|
36
|
+
/** @type {string[]} */
|
|
33
37
|
const invalidArgs = [];
|
|
34
38
|
Object.keys(options).forEach((key) => {
|
|
35
|
-
if (Object.
|
|
39
|
+
if (Object.hasOwn(acceptedOptions, key)) {
|
|
36
40
|
// eslint-disable-next-line valid-typeof
|
|
37
41
|
if (typeof options[key] === acceptedOptions[key].type) {
|
|
38
42
|
// Skip boolean options if false
|
|
43
|
+
|
|
39
44
|
if (acceptedOptions[key].type === "boolean" && !options[key]) {
|
|
40
45
|
return;
|
|
41
46
|
}
|
|
42
47
|
// Arg will be empty for some non-standard options
|
|
48
|
+
|
|
43
49
|
if (acceptedOptions[key].arg !== "") {
|
|
44
50
|
args.push(acceptedOptions[key].arg);
|
|
45
51
|
}
|
|
@@ -58,7 +64,8 @@ function parseOptions(acceptedOptions, options, version) {
|
|
|
58
64
|
if (
|
|
59
65
|
acceptedOptions[key].minVersion &&
|
|
60
66
|
version &&
|
|
61
|
-
|
|
67
|
+
// @ts-ignore: type checking is done above
|
|
68
|
+
lt(version, acceptedOptions[key].minVersion, { loose: true })
|
|
62
69
|
) {
|
|
63
70
|
invalidArgs.push(
|
|
64
71
|
`Invalid option provided for the current version of the binary used. '${key}' was introduced in v${acceptedOptions[key].minVersion}, but received v${version}`
|
|
@@ -75,14 +82,12 @@ function parseOptions(acceptedOptions, options, version) {
|
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
class Poppler {
|
|
78
|
-
/**
|
|
79
|
-
* @param {string=} binPath - Path of poppler-utils binaries.
|
|
80
|
-
*/
|
|
85
|
+
/** @param {string} [binPath] - Path of poppler-utils binaries. */
|
|
81
86
|
constructor(binPath) {
|
|
82
87
|
if (binPath) {
|
|
83
|
-
this.popplerPath =
|
|
88
|
+
this.popplerPath = normalizeTrim(binPath);
|
|
84
89
|
} else if (process.platform === "win32") {
|
|
85
|
-
this.popplerPath =
|
|
90
|
+
this.popplerPath = joinSafe(
|
|
86
91
|
__dirname,
|
|
87
92
|
"lib",
|
|
88
93
|
"win32",
|
|
@@ -103,9 +108,9 @@ class Poppler {
|
|
|
103
108
|
* @param {string} file - Filepath of the PDF file to read.
|
|
104
109
|
* @param {string} fileToAttach - Filepath of the attachment to be embedded into the PDF file.
|
|
105
110
|
* @param {string} outputFile - Filepath of the file to output the results to.
|
|
106
|
-
* @param {object
|
|
107
|
-
* @param {boolean
|
|
108
|
-
* @param {boolean
|
|
111
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
112
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version info.
|
|
113
|
+
* @param {boolean} [options.replace] - Replace embedded file with same name (if it exists).
|
|
109
114
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
110
115
|
*/
|
|
111
116
|
async pdfAttach(file, fileToAttach, outputFile, options = {}) {
|
|
@@ -121,7 +126,7 @@ class Poppler {
|
|
|
121
126
|
args.push(outputFile);
|
|
122
127
|
|
|
123
128
|
const { stdout } = await execFileAsync(
|
|
124
|
-
|
|
129
|
+
joinSafe(this.popplerPath, "pdfattach"),
|
|
125
130
|
args
|
|
126
131
|
);
|
|
127
132
|
return Promise.resolve(stdout);
|
|
@@ -134,26 +139,26 @@ class Poppler {
|
|
|
134
139
|
* @author Frazer Smith
|
|
135
140
|
* @description Lists or extracts embedded files (attachments) from a PDF file.
|
|
136
141
|
* @param {string} file - Filepath of the PDF file to read.
|
|
137
|
-
* @param {object
|
|
138
|
-
* @param {boolean
|
|
142
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
143
|
+
* @param {boolean} [options.listEmbedded] - List all of the embedded files in the PDF file.
|
|
139
144
|
* File names are converted to the text encoding specified by `options.outputEncoding`.
|
|
140
|
-
* @param {string
|
|
141
|
-
* @param {string
|
|
145
|
+
* @param {string} [options.ownerPassword] - Owner password (for encrypted files).
|
|
146
|
+
* @param {string} [options.outputEncoding] - Sets the encoding to use for text output.
|
|
142
147
|
* This defaults to `UTF-8`.
|
|
143
|
-
* @param {string
|
|
148
|
+
* @param {string} [options.outputPath] - Set the file name used when saving an embedded file with
|
|
144
149
|
* the save option enabled, or the directory if `options.saveall` is used.
|
|
145
|
-
* @param {boolean
|
|
146
|
-
* @param {boolean
|
|
150
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version info.
|
|
151
|
+
* @param {boolean} [options.saveAllFiles] - Save all of the embedded files. This uses the file
|
|
147
152
|
* names associated with the embedded files (as printed by `options.listEmbedded`).
|
|
148
153
|
* By default, the files are saved in the current directory; this can be changed
|
|
149
154
|
* with `options.outputPath`.
|
|
150
|
-
* @param {string
|
|
155
|
+
* @param {string} [options.saveFile] - Save the specified embedded file.
|
|
151
156
|
* By default, this uses the file name associated with the embedded file (as printed by
|
|
152
157
|
* `options.listEmbedded`); the file name can be changed with `options.outputPath`.
|
|
153
|
-
* @param {number
|
|
158
|
+
* @param {number} [options.saveSpecificFile] - Save the specified embedded file.
|
|
154
159
|
* By default, this uses the file name associated with the embedded file (as printed by
|
|
155
160
|
* `options.listEmbedded`); the file name can be changed with `options.outputPath`.
|
|
156
|
-
* @param {string
|
|
161
|
+
* @param {string} [options.userPassword] - User password (for encrypted files).
|
|
157
162
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
158
163
|
*/
|
|
159
164
|
async pdfDetach(file, options = {}) {
|
|
@@ -178,7 +183,7 @@ class Poppler {
|
|
|
178
183
|
args.push(file);
|
|
179
184
|
|
|
180
185
|
const { stdout } = await execFileAsync(
|
|
181
|
-
|
|
186
|
+
joinSafe(this.popplerPath, "pdfdetach"),
|
|
182
187
|
args
|
|
183
188
|
);
|
|
184
189
|
return Promise.resolve(stdout);
|
|
@@ -190,15 +195,15 @@ class Poppler {
|
|
|
190
195
|
/**
|
|
191
196
|
* @author Frazer Smith
|
|
192
197
|
* @description Lists the fonts used in a PDF file along with various information for each font.
|
|
193
|
-
* @param {Buffer|
|
|
194
|
-
* @param {object
|
|
195
|
-
* @param {number
|
|
196
|
-
* @param {number
|
|
197
|
-
* @param {boolean
|
|
198
|
+
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
199
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
200
|
+
* @param {number} [options.firstPageToExamine] - Specifies the first page to examine.
|
|
201
|
+
* @param {number} [options.lastPageToExamine] - Specifies the last page to examine.
|
|
202
|
+
* @param {boolean} [options.listSubstitutes] - List the substitute fonts that poppler
|
|
198
203
|
* will use for non-embedded fonts.
|
|
199
|
-
* @param {string
|
|
200
|
-
* @param {boolean
|
|
201
|
-
* @param {string
|
|
204
|
+
* @param {string} [options.ownerPassword] - Owner password (for encrypted files).
|
|
205
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version info.
|
|
206
|
+
* @param {string} [options.userPassword] - User password (for encrypted files). *
|
|
202
207
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
203
208
|
*/
|
|
204
209
|
async pdfFonts(file, options = {}) {
|
|
@@ -213,10 +218,11 @@ class Poppler {
|
|
|
213
218
|
|
|
214
219
|
try {
|
|
215
220
|
const { stderr } = await execFileAsync(
|
|
216
|
-
|
|
221
|
+
joinSafe(this.popplerPath, "pdffonts"),
|
|
217
222
|
["-v"]
|
|
218
223
|
);
|
|
219
224
|
|
|
225
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
220
226
|
const versionInfo = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(stderr)[1];
|
|
221
227
|
|
|
222
228
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
@@ -229,7 +235,7 @@ class Poppler {
|
|
|
229
235
|
}
|
|
230
236
|
|
|
231
237
|
const child = spawn(
|
|
232
|
-
|
|
238
|
+
joinSafe(this.popplerPath, "pdffonts"),
|
|
233
239
|
args
|
|
234
240
|
);
|
|
235
241
|
|
|
@@ -265,25 +271,25 @@ class Poppler {
|
|
|
265
271
|
/**
|
|
266
272
|
* @author Frazer Smith
|
|
267
273
|
* @description Saves images from a PDF file as PPM, PBM, PNG, TIFF, JPEG, JPEG2000, or JBIG2 files.
|
|
268
|
-
* @param {Buffer|
|
|
269
|
-
* @param {string
|
|
270
|
-
* @param {object
|
|
271
|
-
* @param {boolean
|
|
274
|
+
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
275
|
+
* @param {string} [outputPrefix] - Filename prefix of output files.
|
|
276
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
277
|
+
* @param {boolean} [options.allFiles] - Write JPEG, JPEG2000, JBIG2, and CCITT images in their native format.
|
|
272
278
|
* CMYK files are written as TIFF files. All other images are written as PNG files.
|
|
273
|
-
* @param {boolean
|
|
274
|
-
* @param {number
|
|
275
|
-
* @param {number
|
|
276
|
-
* @param {boolean
|
|
279
|
+
* @param {boolean} [options.ccittFile] - Generate CCITT images as CCITT files.
|
|
280
|
+
* @param {number} [options.firstPageToConvert] - Specifies the first page to convert.
|
|
281
|
+
* @param {number} [options.lastPageToConvert] - Specifies the last page to convert.
|
|
282
|
+
* @param {boolean} [options.list] - Instead of writing the images, list the
|
|
277
283
|
* images along with various information for each image.
|
|
278
284
|
* NOTE: Do not specify the outputPrefix with this option.
|
|
279
|
-
* @param {boolean
|
|
280
|
-
* @param {boolean
|
|
281
|
-
* @param {boolean
|
|
282
|
-
* @param {string
|
|
283
|
-
* @param {boolean
|
|
284
|
-
* @param {boolean
|
|
285
|
-
* @param {boolean
|
|
286
|
-
* @param {string
|
|
285
|
+
* @param {boolean} [options.jbig2File] - Generate JBIG2 images as JBIG2 files.
|
|
286
|
+
* @param {boolean} [options.jpeg2000File] - Generate JPEG2000 images at JP2 files.
|
|
287
|
+
* @param {boolean} [options.jpegFile] - Generate JPEG images as JPEG files.
|
|
288
|
+
* @param {string} [options.ownerPassword] - Owner password (for encrypted files).
|
|
289
|
+
* @param {boolean} [options.pngFile] - Change the default output format to PNG.
|
|
290
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version info.
|
|
291
|
+
* @param {boolean} [options.tiffFile] - Change the default output format to TIFF.
|
|
292
|
+
* @param {string} [options.userPassword] - Specify the user password for the PDF file.
|
|
287
293
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
288
294
|
*/
|
|
289
295
|
async pdfImages(file, outputPrefix, options = {}) {
|
|
@@ -305,10 +311,11 @@ class Poppler {
|
|
|
305
311
|
|
|
306
312
|
try {
|
|
307
313
|
const { stderr } = await execFileAsync(
|
|
308
|
-
|
|
314
|
+
joinSafe(this.popplerPath, "pdfimages"),
|
|
309
315
|
["-v"]
|
|
310
316
|
);
|
|
311
317
|
|
|
318
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
312
319
|
const versionInfo = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(stderr)[1];
|
|
313
320
|
|
|
314
321
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
@@ -325,7 +332,7 @@ class Poppler {
|
|
|
325
332
|
}
|
|
326
333
|
|
|
327
334
|
const child = spawn(
|
|
328
|
-
|
|
335
|
+
joinSafe(this.popplerPath, "pdfimages"),
|
|
329
336
|
args
|
|
330
337
|
);
|
|
331
338
|
|
|
@@ -346,6 +353,7 @@ class Poppler {
|
|
|
346
353
|
});
|
|
347
354
|
|
|
348
355
|
child.on("close", (code) => {
|
|
356
|
+
/* istanbul ignore else */
|
|
349
357
|
if (stdOut !== "") {
|
|
350
358
|
resolve(stdOut.trim());
|
|
351
359
|
} else if (code === 0) {
|
|
@@ -353,8 +361,11 @@ class Poppler {
|
|
|
353
361
|
} else if (stdErr !== "") {
|
|
354
362
|
reject(new Error(stdErr.trim()));
|
|
355
363
|
} else {
|
|
356
|
-
|
|
357
|
-
|
|
364
|
+
reject(
|
|
365
|
+
new Error(
|
|
366
|
+
code ? errorMessages[code] : errorMessages.unk
|
|
367
|
+
)
|
|
368
|
+
);
|
|
358
369
|
}
|
|
359
370
|
});
|
|
360
371
|
});
|
|
@@ -366,36 +377,37 @@ class Poppler {
|
|
|
366
377
|
/**
|
|
367
378
|
* @author Frazer Smith
|
|
368
379
|
* @description Prints the contents of the `Info` dictionary from a PDF file.
|
|
369
|
-
* @param {Buffer|
|
|
370
|
-
* @param {object
|
|
371
|
-
* @param {number
|
|
372
|
-
* @param {number
|
|
373
|
-
* @param {boolean
|
|
374
|
-
* @param {string
|
|
380
|
+
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
381
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
382
|
+
* @param {number} [options.firstPageToConvert] - First page to print.
|
|
383
|
+
* @param {number} [options.lastPageToConvert] - Last page to print.
|
|
384
|
+
* @param {boolean} [options.listEncodingOptions] - List the available encodings.
|
|
385
|
+
* @param {string} [options.outputEncoding] - Sets the encoding to use for text output.
|
|
375
386
|
* This defaults to `UTF-8`.
|
|
376
|
-
* @param {string
|
|
377
|
-
* @param {boolean
|
|
378
|
-
* @param {boolean
|
|
387
|
+
* @param {string} [options.ownerPassword] - Owner password (for encrypted files).
|
|
388
|
+
* @param {boolean} [options.printAsJson] - Print result as a JSON object.
|
|
389
|
+
* @param {boolean} [options.printBoundingBoxes] - Prints the page box bounding boxes:
|
|
379
390
|
* MediaBox, CropBox, BleedBox, TrimBox, and ArtBox.
|
|
380
|
-
* @param {boolean
|
|
391
|
+
* @param {boolean} [options.printDocStruct] - Prints the logical document structure
|
|
381
392
|
* of a Tagged-PDF file.
|
|
382
|
-
* @param {boolean
|
|
393
|
+
* @param {boolean} [options.printDocStructText] - Print the textual content along with the
|
|
383
394
|
* document structure of a Tagged-PDF file. Note that extracting text this way might be slow
|
|
384
395
|
*
|
|
385
396
|
* for big PDF files.
|
|
386
|
-
* @param {boolean
|
|
387
|
-
* @param {boolean
|
|
388
|
-
* @param {boolean
|
|
397
|
+
* @param {boolean} [options.printIsoDates] - Prints dates in ISO-8601 format (including the time zone).
|
|
398
|
+
* @param {boolean} [options.printJS] - Prints all JavaScript in the PDF file.
|
|
399
|
+
* @param {boolean} [options.printMetadata] - Prints document-level metadata. (This is the `Metadata`
|
|
389
400
|
* stream from the PDF file's Catalog object).
|
|
390
|
-
* @param {boolean
|
|
401
|
+
* @param {boolean} [options.printNamedDests] - Print a list of all named destinations. If a page range
|
|
391
402
|
* is specified using the `options.firstPageToConvert` and `options.lastPageToConvert` options, only destinations
|
|
392
403
|
* in the page range are listed.
|
|
393
|
-
* @param {boolean
|
|
394
|
-
* @param {boolean
|
|
404
|
+
* @param {boolean} [options.printRawDates] - Prints the raw (undecoded) date strings, directly from the PDF file.
|
|
405
|
+
* @param {boolean} [options.printUrls] - Print all URLs in the PDF; only URLs referenced by PDF objects
|
|
395
406
|
* such as Link Annotations are listed, not URL strings in the text content.
|
|
396
|
-
* @param {boolean
|
|
397
|
-
* @param {string
|
|
398
|
-
* @returns {Promise<string>} A promise that resolves with a stdout string
|
|
407
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version info.
|
|
408
|
+
* @param {string} [options.userPassword] - User password (for encrypted files).
|
|
409
|
+
* @returns {Promise<object|string>} A promise that resolves with a stdout string or JSON object if
|
|
410
|
+
* `options.printAsJson` is `true`, or rejects with an `Error` object.
|
|
399
411
|
*/
|
|
400
412
|
async pdfInfo(file, options = {}) {
|
|
401
413
|
const acceptedOptions = {
|
|
@@ -420,10 +432,11 @@ class Poppler {
|
|
|
420
432
|
|
|
421
433
|
try {
|
|
422
434
|
const { stderr } = await execFileAsync(
|
|
423
|
-
|
|
435
|
+
joinSafe(this.popplerPath, "pdfinfo"),
|
|
424
436
|
["-v"]
|
|
425
437
|
);
|
|
426
438
|
|
|
439
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
427
440
|
const versionInfo = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(stderr)[1];
|
|
428
441
|
|
|
429
442
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
@@ -432,6 +445,7 @@ class Poppler {
|
|
|
432
445
|
* Poppler does not set the "File size" metadata value if passed
|
|
433
446
|
* a Buffer via stdin, so need to retrieve it from the Buffer
|
|
434
447
|
*/
|
|
448
|
+
/** @type {number} */
|
|
435
449
|
let fileSize;
|
|
436
450
|
|
|
437
451
|
return new Promise((resolve, reject) => {
|
|
@@ -442,8 +456,8 @@ class Poppler {
|
|
|
442
456
|
args.push(file);
|
|
443
457
|
}
|
|
444
458
|
|
|
445
|
-
const child =
|
|
446
|
-
|
|
459
|
+
const child = spawn(
|
|
460
|
+
joinSafe(this.popplerPath, "pdfinfo"),
|
|
447
461
|
args
|
|
448
462
|
);
|
|
449
463
|
|
|
@@ -472,15 +486,16 @@ class Poppler {
|
|
|
472
486
|
);
|
|
473
487
|
}
|
|
474
488
|
|
|
489
|
+
/**
|
|
490
|
+
* Convert output to JSON.
|
|
491
|
+
* @see {@link https://github.com/Fdawgs/node-poppler/issues/248#issuecomment-845948080 | Node-Poppler Issue #248}
|
|
492
|
+
*/
|
|
475
493
|
if (options.printAsJson === true) {
|
|
476
|
-
/**
|
|
477
|
-
* Thanks to @sainf for this solution
|
|
478
|
-
* https://github.com/Fdawgs/node-poppler/issues/248#issuecomment-845948080
|
|
479
|
-
*/
|
|
480
494
|
const info = {};
|
|
481
495
|
stdOut.split("\n").forEach((line) => {
|
|
482
496
|
const lines = line.split(": ");
|
|
483
497
|
if (lines.length > 1) {
|
|
498
|
+
// @ts-ignore: creating dynamic object keys
|
|
484
499
|
info[camelCase(lines[0])] = lines[1].trim();
|
|
485
500
|
}
|
|
486
501
|
});
|
|
@@ -507,12 +522,12 @@ class Poppler {
|
|
|
507
522
|
* @param {string} outputPattern - Should contain %d (or any variant respecting printf format),
|
|
508
523
|
* since %d is replaced by the page number.
|
|
509
524
|
* As an example, `sample-%d.pdf` will produce `sample-1.pdf` for a single page document.
|
|
510
|
-
* @param {object
|
|
511
|
-
* @param {number
|
|
525
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
526
|
+
* @param {number} [options.firstPageToExtract] - Specifies the first page to extract.
|
|
512
527
|
* This defaults to page 1.
|
|
513
|
-
* @param {number
|
|
528
|
+
* @param {number} [options.lastPageToExtract] - Specifies the last page to extract.
|
|
514
529
|
* This defaults to the last page of the PDF file.
|
|
515
|
-
* @param {boolean
|
|
530
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version info.
|
|
516
531
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
517
532
|
*/
|
|
518
533
|
async pdfSeparate(file, outputPattern, options = {}) {
|
|
@@ -524,10 +539,11 @@ class Poppler {
|
|
|
524
539
|
|
|
525
540
|
try {
|
|
526
541
|
const { stderr } = await execFileAsync(
|
|
527
|
-
|
|
542
|
+
joinSafe(this.popplerPath, "pdfseparate"),
|
|
528
543
|
["-v"]
|
|
529
544
|
);
|
|
530
545
|
|
|
546
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
531
547
|
const versionInfo = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(stderr)[1];
|
|
532
548
|
|
|
533
549
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
@@ -535,7 +551,7 @@ class Poppler {
|
|
|
535
551
|
args.push(outputPattern);
|
|
536
552
|
|
|
537
553
|
const { stdout } = await execFileAsync(
|
|
538
|
-
|
|
554
|
+
joinSafe(this.popplerPath, "pdfseparate"),
|
|
539
555
|
args
|
|
540
556
|
);
|
|
541
557
|
return Promise.resolve(stdout);
|
|
@@ -547,45 +563,45 @@ class Poppler {
|
|
|
547
563
|
/**
|
|
548
564
|
* @author Frazer Smith
|
|
549
565
|
* @description Converts a PDF file to EPS/JPEG/PDF/PNG/PS/SVG/TIFF.
|
|
550
|
-
* @param {Buffer|
|
|
551
|
-
* @param {string
|
|
566
|
+
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
567
|
+
* @param {string} [outputFile] - Filepath of the file to output the results to.
|
|
552
568
|
*
|
|
553
569
|
* If `undefined` then will write output to stdout. Using stdout is not valid with image formats
|
|
554
570
|
* (jpeg, png, and tiff) unless `options.singleFile` is set to `true`.
|
|
555
571
|
* Encoding is set to `binary` if used with `options.singleFile` or `options.pdfFile`.
|
|
556
572
|
*
|
|
557
573
|
* If not set then the output filename will be derived from the PDF file name.
|
|
558
|
-
* @param {object
|
|
559
|
-
* @param {('
|
|
574
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
575
|
+
* @param {('best'|'default'|'fast'|'good'|'gray'|'none'|'subpixel')} [options.antialias] - Set the cairo
|
|
560
576
|
* antialias option used for text and drawing in image files (or rasterized regions in vector output).
|
|
561
|
-
* @param {boolean
|
|
577
|
+
* @param {boolean} [options.cropBox] - Uses the crop box rather than media box when
|
|
562
578
|
* generating the files (PNG/JPEG/TIFF only).
|
|
563
|
-
* @param {number
|
|
579
|
+
* @param {number} [options.cropHeight] - Specifies the height of crop area in pixels
|
|
564
580
|
* (image output) or points (vector output).
|
|
565
|
-
* @param {number
|
|
581
|
+
* @param {number} [options.cropSize] - Specifies the size of crop square in pixels
|
|
566
582
|
* (image output) or points (vector output).
|
|
567
|
-
* @param {number
|
|
583
|
+
* @param {number} [options.cropWidth] - Specifies the width of crop area in pixels
|
|
568
584
|
* (image output) or points (vector output).
|
|
569
|
-
* @param {number
|
|
585
|
+
* @param {number} [options.cropXAxis] - Specifies the x-coordinate of the crop area top left
|
|
570
586
|
* corner in pixels (image output) or points (vector output).
|
|
571
|
-
* @param {number
|
|
587
|
+
* @param {number} [options.cropYAxis] - Specifies the y-coordinate of the crop area top left
|
|
572
588
|
* corner in pixels (image output) or points (vector output).
|
|
573
|
-
* @param {boolean
|
|
589
|
+
* @param {boolean} [options.duplex] - Adds the %%IncludeFeature: *Duplex DuplexNoTumble DSC
|
|
574
590
|
* comment to the PostScript file (PS only). This tells the print manager to enable duplexing.
|
|
575
|
-
* @param {boolean
|
|
591
|
+
* @param {boolean} [options.epsFile] - Generate an EPS file. An EPS file contains a single image,
|
|
576
592
|
* so if you use this option with a multi-page PDF file, you must use `options.firstPageToConvert` and
|
|
577
593
|
* `options.lastPageToConvert` to specify a single page.
|
|
578
594
|
* The page size options (originalPageSizes, paperSize, paperWidth, paperHeight) can not be used
|
|
579
595
|
* with this option.
|
|
580
|
-
* @param {boolean
|
|
581
|
-
* @param {boolean
|
|
596
|
+
* @param {boolean} [options.evenPagesOnly] - Generates only the even numbered pages.
|
|
597
|
+
* @param {boolean} [options.fillPage] - Expand PDF pages smaller than the paper to fill the
|
|
582
598
|
* paper (PS,PDF,SVG only). By default, these pages are not scaled.
|
|
583
|
-
* @param {number
|
|
584
|
-
* @param {boolean
|
|
585
|
-
* @param {string
|
|
599
|
+
* @param {number} [options.firstPageToConvert] - Specifies the first page to convert.
|
|
600
|
+
* @param {boolean} [options.grayscaleFile] - Generate grayscale file (PNG, JPEG, and TIFF only).
|
|
601
|
+
* @param {string} [options.iccFile] - Use the specified ICC file as the output profile
|
|
586
602
|
* (PNG only). The profile will be embedded in the PNG file.
|
|
587
|
-
* @param {boolean
|
|
588
|
-
* @param {string
|
|
603
|
+
* @param {boolean} [options.jpegFile] - Generate JPEG file(s).
|
|
604
|
+
* @param {string} [options.jpegOptions] - When used with `options.jpegFile`, this option can
|
|
589
605
|
* be used to control the JPEG compression parameters. It takes a string of the form
|
|
590
606
|
* `"<opt>=<val>[,<opt>=<val>]"`. Currently available options are:
|
|
591
607
|
* - `quality` Selects the JPEG quality value. The value must be an integer between 0 and 100.
|
|
@@ -596,57 +612,57 @@ class Poppler {
|
|
|
596
612
|
* with "y" performing optimization, otherwise the default Huffman tables are used.
|
|
597
613
|
*
|
|
598
614
|
* Example: `"quality=95,optimize=y"`.
|
|
599
|
-
* @param {number
|
|
600
|
-
* @param {boolean
|
|
601
|
-
* @param {boolean
|
|
615
|
+
* @param {number} [options.lastPageToConvert] - Specifies the last page to convert.
|
|
616
|
+
* @param {boolean} [options.monochromeFile] - Generate monochrome file (PNG and TIFF only).
|
|
617
|
+
* @param {boolean} [options.noCenter] - By default, PDF pages smaller than the paper
|
|
602
618
|
* (after any scaling) are centered on the paper. This option causes them to be aligned to
|
|
603
619
|
* the lower-left corner of the paper instead (PS,PDF,SVG only).
|
|
604
|
-
* @param {boolean
|
|
620
|
+
* @param {boolean} [options.noCrop] - By default, printing output is cropped to the CropBox
|
|
605
621
|
* specified in the PDF file. This option disables cropping (PS, PDF, SVG only).
|
|
606
|
-
* @param {boolean
|
|
622
|
+
* @param {boolean} [options.noShrink] - Do not scale PDF pages which are larger than the paper
|
|
607
623
|
* (PS,PDF,SVG only). By default, pages larger than the paper are shrunk to fit.
|
|
608
|
-
* @param {boolean
|
|
609
|
-
* @param {boolean
|
|
624
|
+
* @param {boolean} [options.oddPagesOnly] - Generates only the odd numbered pages.
|
|
625
|
+
* @param {boolean} [options.originalPageSizes] - Set the paper size of each page to match
|
|
610
626
|
* the size specified in the PDF file.
|
|
611
|
-
* @param {string
|
|
627
|
+
* @param {string} [options.ownerPassword] - Specify the owner password for the PDF file.
|
|
612
628
|
* Providing this will bypass all security restrictions.
|
|
613
|
-
* @param {number
|
|
614
|
-
* @param {('
|
|
615
|
-
* or `
|
|
629
|
+
* @param {number} [options.paperHeight] - Set the paper height, in points (PS, PDF, SVG only).
|
|
630
|
+
* @param {('A3'|'A4'|'legal'|'letter'|'match')} [options.paperSize] - Set the paper size to one of `A3`, `A4`,
|
|
631
|
+
* `legal`, or `letter` (PS,PDF,SVG only). This can also be set to `match`, which will set the paper size
|
|
616
632
|
* of each page to match the size specified in the PDF file. If none of the paperSize,
|
|
617
633
|
* paperWidth, or paperHeight options are specified the default is to match the paper size.
|
|
618
|
-
* @param {number
|
|
619
|
-
* @param {boolean
|
|
620
|
-
* @param {boolean
|
|
621
|
-
* @param {boolean
|
|
622
|
-
* @param {boolean
|
|
623
|
-
* @param {boolean
|
|
624
|
-
* @param {boolean
|
|
634
|
+
* @param {number} [options.paperWidth] - Set the paper width, in points (PS,PDF,SVG only).
|
|
635
|
+
* @param {boolean} [options.pdfFile] - Generate PDF file.
|
|
636
|
+
* @param {boolean} [options.pngFile] - Generate PNG file(s).
|
|
637
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version information.
|
|
638
|
+
* @param {boolean} [options.psFile] - Generate PS file.
|
|
639
|
+
* @param {boolean} [options.psLevel2] - Generate Level 2 PostScript (PS only).
|
|
640
|
+
* @param {boolean} [options.psLevel3] - Generate Level 3 PostScript (PS only). This enables all
|
|
625
641
|
* Level 2 features plus shading patterns and masked images. This is the default setting.
|
|
626
|
-
* @param {boolean
|
|
627
|
-
* @param {number
|
|
642
|
+
* @param {boolean} [options.quiet] - Do not print any messages or errors.
|
|
643
|
+
* @param {number} [options.resolutionXAxis] - Specifies the X resolution, in pixels per inch of
|
|
628
644
|
* image files (or rasterized regions in vector output). The default is 150 PPI.
|
|
629
|
-
* @param {number
|
|
645
|
+
* @param {number} [options.resolutionXYAxis] - Specifies the X and Y resolution, in pixels per
|
|
630
646
|
* inch of image files (or rasterized regions in vector output). The default is 150 PPI.
|
|
631
|
-
* @param {number
|
|
647
|
+
* @param {number} [options.resolutionYAxis] - Specifies the Y resolution, in pixels per inch of
|
|
632
648
|
* image files (or rasterized regions in vector output). The default is 150 PPI.
|
|
633
|
-
* @param {number
|
|
649
|
+
* @param {number} [options.scalePageTo] - Scales the long side of each page (width for landscape
|
|
634
650
|
* pages, height for portrait pages) to fit in scale-to pixels. The size of the short side will
|
|
635
651
|
* be determined by the aspect ratio of the page (PNG/JPEG/TIFF only).
|
|
636
|
-
* @param {number
|
|
652
|
+
* @param {number} [options.scalePageToXAxis] - Scales each page horizontally to fit in scale-to-x
|
|
637
653
|
* pixels. If scale-to-y is set to -1, the vertical size will determined by the aspect ratio of
|
|
638
654
|
* the page (PNG/JPEG/TIFF only).
|
|
639
|
-
* @param {number
|
|
655
|
+
* @param {number} [options.scalePageToYAxis] - Scales each page vertically to fit in scale-to-y
|
|
640
656
|
* pixels. If scale-to-x is set to -1, the horizontal size will determined by the aspect ratio of
|
|
641
657
|
* the page (PNG/JPEG/TIFF only).
|
|
642
|
-
* @param {boolean
|
|
658
|
+
* @param {boolean} [options.singleFile] - Writes only the first page and does not add digits.
|
|
643
659
|
* Can only be used with `options.jpegFile`, `options.pngFile`, and `options.tiffFile`.
|
|
644
|
-
* @param {boolean
|
|
645
|
-
* @param {('
|
|
646
|
-
* @param {boolean
|
|
647
|
-
* @param {boolean
|
|
660
|
+
* @param {boolean} [options.svgFile] - Generate SVG (Scalable Vector Graphics) file.
|
|
661
|
+
* @param {('deflate'|'jpeg'|'lzw'|'none'|'packbits')} [options.tiffCompression] - Set TIFF compression.
|
|
662
|
+
* @param {boolean} [options.tiffFile] - Generate TIFF file(s).
|
|
663
|
+
* @param {boolean} [options.transparentPageColor] - Use a transparent page color
|
|
648
664
|
* instead of white (PNG and TIFF only).
|
|
649
|
-
* @param {string
|
|
665
|
+
* @param {string} [options.userPassword] - Specify the user password for the PDF file.
|
|
650
666
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
651
667
|
*/
|
|
652
668
|
async pdfToCairo(file, outputFile, options = {}) {
|
|
@@ -701,10 +717,11 @@ class Poppler {
|
|
|
701
717
|
|
|
702
718
|
try {
|
|
703
719
|
const { stderr } = await execFileAsync(
|
|
704
|
-
|
|
720
|
+
joinSafe(this.popplerPath, "pdftocairo"),
|
|
705
721
|
["-v"]
|
|
706
722
|
);
|
|
707
723
|
|
|
724
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
708
725
|
const versionInfo = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(stderr)[1];
|
|
709
726
|
|
|
710
727
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
@@ -723,7 +740,7 @@ class Poppler {
|
|
|
723
740
|
}
|
|
724
741
|
|
|
725
742
|
const child = spawn(
|
|
726
|
-
|
|
743
|
+
joinSafe(this.popplerPath, "pdftocairo"),
|
|
727
744
|
args
|
|
728
745
|
);
|
|
729
746
|
|
|
@@ -751,6 +768,7 @@ class Poppler {
|
|
|
751
768
|
});
|
|
752
769
|
|
|
753
770
|
child.on("close", (code) => {
|
|
771
|
+
/* istanbul ignore else */
|
|
754
772
|
if (stdOut !== "") {
|
|
755
773
|
resolve(stdOut.trim());
|
|
756
774
|
} else if (code === 0) {
|
|
@@ -758,8 +776,11 @@ class Poppler {
|
|
|
758
776
|
} else if (stdErr !== "") {
|
|
759
777
|
reject(new Error(stdErr.trim()));
|
|
760
778
|
} else {
|
|
761
|
-
|
|
762
|
-
|
|
779
|
+
reject(
|
|
780
|
+
new Error(
|
|
781
|
+
code ? errorMessages[code] : errorMessages.unk
|
|
782
|
+
)
|
|
783
|
+
);
|
|
763
784
|
}
|
|
764
785
|
});
|
|
765
786
|
});
|
|
@@ -771,41 +792,41 @@ class Poppler {
|
|
|
771
792
|
/**
|
|
772
793
|
* @author Frazer Smith
|
|
773
794
|
* @description Converts a PDF file to HTML.
|
|
774
|
-
* @param {Buffer|
|
|
775
|
-
* @param {string
|
|
795
|
+
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
796
|
+
* @param {string} [outputFile] - Filepath of the file to output the results to.
|
|
776
797
|
* If `undefined` then Poppler will use the directory and name of the original file
|
|
777
798
|
* and create a new file, with `-html` appended to the end of the filename.
|
|
778
799
|
*
|
|
779
800
|
* Required if `file` is a Buffer.
|
|
780
|
-
* @param {object
|
|
781
|
-
* @param {boolean
|
|
782
|
-
* @param {boolean
|
|
783
|
-
* @param {boolean
|
|
784
|
-
* @param {boolean
|
|
785
|
-
* @param {number
|
|
786
|
-
* @param {boolean
|
|
787
|
-
* @param {boolean
|
|
788
|
-
* @param {('
|
|
801
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
802
|
+
* @param {boolean} [options.complexOutput] - Generate complex output.
|
|
803
|
+
* @param {boolean} [options.dataUrls] - Use data URLs instead of external images in HTML.
|
|
804
|
+
* @param {boolean} [options.exchangePdfLinks] - Exchange .pdf links with .html.
|
|
805
|
+
* @param {boolean} [options.extractHidden] - Force hidden text extraction.
|
|
806
|
+
* @param {number} [options.firstPageToConvert] - First page to print.
|
|
807
|
+
* @param {boolean} [options.fontFullName] - Outputs the font name without any substitutions.
|
|
808
|
+
* @param {boolean} [options.ignoreImages] - Ignore images.
|
|
809
|
+
* @param {('JPG'|'PNG')} [options.imageFormat] - Image file format for Splash output (JPG or PNG).
|
|
789
810
|
* If complexOutput is selected, but imageFormat is not specified, PNG will be assumed.
|
|
790
|
-
* @param {number
|
|
791
|
-
* @param {boolean
|
|
792
|
-
* @param {boolean
|
|
793
|
-
* @param {boolean
|
|
794
|
-
* @param {boolean
|
|
811
|
+
* @param {number} [options.lastPageToConvert] - Last page to print.
|
|
812
|
+
* @param {boolean} [options.noDrm] - Override document DRM settings.
|
|
813
|
+
* @param {boolean} [options.noFrames] - Generate no frames. Not supported in complex output mode.
|
|
814
|
+
* @param {boolean} [options.noMergeParagraph] - Do not merge paragraphs.
|
|
815
|
+
* @param {boolean} [options.noRoundedCoordinates] - Do not round coordinates
|
|
795
816
|
* (with XML output only).
|
|
796
|
-
* @param {string
|
|
817
|
+
* @param {string} [options.outputEncoding] - Sets the encoding to use for text output.
|
|
797
818
|
* This defaults to `UTF-8`.
|
|
798
|
-
* @param {string
|
|
799
|
-
* @param {boolean
|
|
800
|
-
* @param {boolean
|
|
801
|
-
* @param {boolean
|
|
802
|
-
* @param {boolean
|
|
803
|
-
* @param {string
|
|
804
|
-
* @param {number
|
|
819
|
+
* @param {string} [options.ownerPassword] - Owner password (for encrypted files).
|
|
820
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version info.
|
|
821
|
+
* @param {boolean} [options.quiet] - Do not print any messages or errors.
|
|
822
|
+
* @param {boolean} [options.singlePage] - generate single HTML that includes all pages.
|
|
823
|
+
* @param {boolean} [options.stdout] - Use standard output.
|
|
824
|
+
* @param {string} [options.userPassword] - User password (for encrypted files).
|
|
825
|
+
* @param {number} [options.wordBreakThreshold] - Adjust the word break threshold percent.
|
|
805
826
|
* Default is 10. Word break occurs when distance between two adjacent characters is greater
|
|
806
827
|
* than this percent of character height.
|
|
807
|
-
* @param {boolean
|
|
808
|
-
* @param {number
|
|
828
|
+
* @param {boolean} [options.xmlOutput] - Output for XML post-processing.
|
|
829
|
+
* @param {number} [options.zoom] - Zoom the PDF document (default 1.5).
|
|
809
830
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
810
831
|
*/
|
|
811
832
|
async pdfToHtml(file, outputFile, options = {}) {
|
|
@@ -841,10 +862,11 @@ class Poppler {
|
|
|
841
862
|
|
|
842
863
|
try {
|
|
843
864
|
const { stderr } = await execFileAsync(
|
|
844
|
-
|
|
865
|
+
joinSafe(this.popplerPath, "pdftohtml"),
|
|
845
866
|
["-v"]
|
|
846
867
|
);
|
|
847
868
|
|
|
869
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
848
870
|
const versionInfo = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(stderr)[1];
|
|
849
871
|
|
|
850
872
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
@@ -861,7 +883,7 @@ class Poppler {
|
|
|
861
883
|
}
|
|
862
884
|
|
|
863
885
|
const child = spawn(
|
|
864
|
-
|
|
886
|
+
joinSafe(this.popplerPath, "pdftohtml"),
|
|
865
887
|
args
|
|
866
888
|
);
|
|
867
889
|
|
|
@@ -883,7 +905,7 @@ class Poppler {
|
|
|
883
905
|
|
|
884
906
|
/**
|
|
885
907
|
* pdfToHtml does not return an exit code so check output to see if it was successful.
|
|
886
|
-
*
|
|
908
|
+
* @see {@link https://gitlab.freedesktop.org/poppler/poppler/-/blob/master/utils/pdftohtml.1 | Poppler pdftohtml man}
|
|
887
909
|
*/
|
|
888
910
|
child.on("close", () => {
|
|
889
911
|
if (stdOut !== "") {
|
|
@@ -903,73 +925,73 @@ class Poppler {
|
|
|
903
925
|
* @description Converts a PDF file to colour image files in Portable Pixmap (PPM) format,
|
|
904
926
|
* grayscale image files in Portable Graymap (PGM) format, or monochrome image files
|
|
905
927
|
* in Portable Bitmap (PBM) format.
|
|
906
|
-
* @param {Buffer|
|
|
928
|
+
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
907
929
|
* @param {string} outputPath - Filepath to output the results to.
|
|
908
|
-
* @param {object
|
|
909
|
-
* @param {('
|
|
930
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
931
|
+
* @param {('no'|'yes')} [options.antialiasFonts] - Enable or disable font anti-aliasing.
|
|
910
932
|
* This defaults to `yes`.
|
|
911
|
-
* @param {('
|
|
933
|
+
* @param {('no'|'yes')} [options.antialiasVectors] - Enable or disable vector anti-aliasing.
|
|
912
934
|
* This defaults to `yes`.
|
|
913
|
-
* @param {boolean
|
|
935
|
+
* @param {boolean} [options.cropBox] - Uses the crop box rather than media box when
|
|
914
936
|
* generating the files (PNG/JPEG/TIFF only).
|
|
915
|
-
* @param {number
|
|
937
|
+
* @param {number} [options.cropHeight] - Specifies the height of crop area in pixels
|
|
916
938
|
* (image output) or points (vector output).
|
|
917
|
-
* @param {number
|
|
939
|
+
* @param {number} [options.cropSize] - Specifies the size of crop square in pixels
|
|
918
940
|
* (image output) or points (vector output).
|
|
919
|
-
* @param {number
|
|
941
|
+
* @param {number} [options.cropWidth] - Specifies the width of crop area in pixels
|
|
920
942
|
* (image output) or points (vector output).
|
|
921
|
-
* @param {number
|
|
943
|
+
* @param {number} [options.cropXAxis] - Specifies the x-coordinate of the crop area top left
|
|
922
944
|
* corner in pixels (image output) or points (vector output).
|
|
923
|
-
* @param {number
|
|
945
|
+
* @param {number} [options.cropYAxis] - Specifies the y-coordinate of the crop area top left
|
|
924
946
|
* corner in pixels (image output) or points (vector output).
|
|
925
|
-
* @param {string
|
|
947
|
+
* @param {string} [options.defaultCmykProfile] - If Poppler is compiled with colour management support, this option
|
|
926
948
|
* sets the DefaultCMYK color space to the ICC profile stored in the display profile file passed.
|
|
927
|
-
* @param {string
|
|
949
|
+
* @param {string} [options.defaultGrayProfile] - If Poppler is compiled with colour management support, this option
|
|
928
950
|
* sets the DefaultGray color space to the ICC profile stored in the display profile file passed.
|
|
929
|
-
* @param {string
|
|
951
|
+
* @param {string} [options.defaultRgbProfile] - If Poppler is compiled with colour management support, this option
|
|
930
952
|
* sets the DefaultRGB color space to the ICC profile stored in the display profile file passed.
|
|
931
|
-
* @param {string
|
|
953
|
+
* @param {string} [options.displayProfile] - If Poppler is compiled with colour management support, this option
|
|
932
954
|
* sets the display profile to the ICC profile stored in the display profile file passed.
|
|
933
|
-
* @param {boolean
|
|
934
|
-
* @param {number
|
|
935
|
-
* @param {('
|
|
955
|
+
* @param {boolean} [options.evenPagesOnly] - Generates only the even numbered pages.
|
|
956
|
+
* @param {number} [options.firstPageToConvert] - Specifies the first page to convert.
|
|
957
|
+
* @param {('no'|'yes')} [options.freetype] - Enable or disable FreeType (a TrueType / Type 1 font rasterizer).
|
|
936
958
|
* This defaults to `yes`.
|
|
937
|
-
* @param {boolean
|
|
938
|
-
* @param {boolean
|
|
939
|
-
* @param {boolean
|
|
940
|
-
* @param {boolean
|
|
941
|
-
* @param {number
|
|
942
|
-
* @param {boolean
|
|
943
|
-
* @param {boolean
|
|
944
|
-
* @param {string
|
|
959
|
+
* @param {boolean} [options.forcePageNumber] - Force page number even if there is only one page.
|
|
960
|
+
* @param {boolean} [options.grayscaleFile] - Generate grayscale PGM file (instead of a color PPM file).
|
|
961
|
+
* @param {boolean} [options.hideAnnotations] - Hide annotations.
|
|
962
|
+
* @param {boolean} [options.jpegFile] - Generate JPEG file instead a PPM file.
|
|
963
|
+
* @param {number} [options.lastPageToConvert] - Specifies the last page to convert.
|
|
964
|
+
* @param {boolean} [options.monochromeFile] - Generate monochrome PBM file (instead of a color PPM file).
|
|
965
|
+
* @param {boolean} [options.oddPagesOnly] - Generates only the odd numbered pages.
|
|
966
|
+
* @param {string} [options.ownerPassword] - Specify the owner password for the PDF file.
|
|
945
967
|
* Providing this will bypass all security restrictions.
|
|
946
|
-
* @param {boolean
|
|
947
|
-
* @param {boolean
|
|
968
|
+
* @param {boolean} [options.pngFile] - Generate PNG file instead a PPM file.
|
|
969
|
+
* @param {boolean} [options.printProgress] - Print progress info as each page is generated.
|
|
948
970
|
* Three space-separated fields are printed to STDERR: the number of the current page, the number
|
|
949
971
|
* of the last page that will be generated, and the path to the file written to.
|
|
950
|
-
* @param {boolean
|
|
951
|
-
* @param {boolean
|
|
952
|
-
* @param {number
|
|
972
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version information.
|
|
973
|
+
* @param {boolean} [options.quiet] - Do not print any messages or errors.
|
|
974
|
+
* @param {number} [options.resolutionXAxis] - Specifies the X resolution, in pixels per inch of
|
|
953
975
|
* image files (or rasterized regions in vector output). The default is 150 PPI.
|
|
954
|
-
* @param {number
|
|
976
|
+
* @param {number} [options.resolutionXYAxis] - Specifies the X and Y resolution, in pixels per
|
|
955
977
|
* inch of image files (or rasterized regions in vector output). The default is 150 PPI.
|
|
956
|
-
* @param {number
|
|
978
|
+
* @param {number} [options.resolutionYAxis] - Specifies the Y resolution, in pixels per inch of
|
|
957
979
|
* image files (or rasterized regions in vector output). The default is 150 PPI.
|
|
958
|
-
* @param {number
|
|
980
|
+
* @param {number} [options.scalePageTo] - Scales the long side of each page (width for landscape
|
|
959
981
|
* pages, height for portrait pages) to fit in scale-to pixels. The size of the short side will
|
|
960
982
|
* be determined by the aspect ratio of the page.
|
|
961
|
-
* @param {number
|
|
983
|
+
* @param {number} [options.scalePageToXAxis] - Scales each page horizontally to fit in scale-to-x
|
|
962
984
|
* pixels. If scale-to-y is set to -1, the vertical size will determined by the aspect ratio of
|
|
963
985
|
* the page.
|
|
964
|
-
* @param {number
|
|
986
|
+
* @param {number} [options.scalePageToYAxis] - Scales each page vertically to fit in scale-to-y
|
|
965
987
|
* pixels. If scale-to-x is set to -1, the horizontal size will determined by the aspect ratio of
|
|
966
988
|
* the page.
|
|
967
|
-
* @param {string
|
|
968
|
-
* @param {boolean
|
|
969
|
-
* @param {('none'|'
|
|
970
|
-
* @param {('
|
|
971
|
-
* @param {boolean
|
|
972
|
-
* @param {string
|
|
989
|
+
* @param {string} [options.separator] - Specify single character separator between name and page number.
|
|
990
|
+
* @param {boolean} [options.singleFile] - Writes only the first page and does not add digits.
|
|
991
|
+
* @param {('none'|'shape'|'solid')} [options.thinLineMode] - Specifies the thin line mode. This defaults to `none`.
|
|
992
|
+
* @param {('deflate'|'jpeg'|'lzw'|'none'|'packbits')} [options.tiffCompression] - Set TIFF compression.
|
|
993
|
+
* @param {boolean} [options.tiffFile] - Generate TIFF file instead a PPM file.
|
|
994
|
+
* @param {string} [options.userPassword] - Specify the user password for the PDF file.
|
|
973
995
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
974
996
|
*/
|
|
975
997
|
async pdfToPpm(file, outputPath, options = {}) {
|
|
@@ -1045,10 +1067,11 @@ class Poppler {
|
|
|
1045
1067
|
|
|
1046
1068
|
try {
|
|
1047
1069
|
const { stderr } = await execFileAsync(
|
|
1048
|
-
|
|
1070
|
+
joinSafe(this.popplerPath, "pdftoppm"),
|
|
1049
1071
|
["-v"]
|
|
1050
1072
|
);
|
|
1051
1073
|
|
|
1074
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
1052
1075
|
const versionInfo = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(stderr)[1];
|
|
1053
1076
|
|
|
1054
1077
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
@@ -1063,7 +1086,7 @@ class Poppler {
|
|
|
1063
1086
|
args.push(outputPath);
|
|
1064
1087
|
|
|
1065
1088
|
const child = spawn(
|
|
1066
|
-
|
|
1089
|
+
joinSafe(this.popplerPath, "pdftoppm"),
|
|
1067
1090
|
args
|
|
1068
1091
|
);
|
|
1069
1092
|
|
|
@@ -1079,13 +1102,17 @@ class Poppler {
|
|
|
1079
1102
|
});
|
|
1080
1103
|
|
|
1081
1104
|
child.on("close", (code) => {
|
|
1105
|
+
/* istanbul ignore else */
|
|
1082
1106
|
if (stdErr !== "") {
|
|
1083
1107
|
reject(new Error(stdErr.trim()));
|
|
1084
1108
|
} else if (code === 0) {
|
|
1085
1109
|
resolve(errorMessages[code]);
|
|
1086
1110
|
} else {
|
|
1087
|
-
|
|
1088
|
-
|
|
1111
|
+
reject(
|
|
1112
|
+
new Error(
|
|
1113
|
+
code ? errorMessages[code] : errorMessages.unk
|
|
1114
|
+
)
|
|
1115
|
+
);
|
|
1089
1116
|
}
|
|
1090
1117
|
});
|
|
1091
1118
|
});
|
|
@@ -1097,110 +1124,110 @@ class Poppler {
|
|
|
1097
1124
|
/**
|
|
1098
1125
|
* @author Frazer Smith
|
|
1099
1126
|
* @description Converts a PDF file to PostScript (PS).
|
|
1100
|
-
* @param {Buffer|
|
|
1101
|
-
* @param {string
|
|
1127
|
+
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
1128
|
+
* @param {string} [outputFile] - Filepath of the file to output the results to.
|
|
1102
1129
|
* If `undefined` then will write output to stdout.
|
|
1103
|
-
* @param {object
|
|
1104
|
-
* @param {('
|
|
1105
|
-
* @param {boolean
|
|
1130
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
1131
|
+
* @param {('no'|'yes')} [options.antialias] - Enable anti-aliasing on rasterization, accepts `no` or `yes`.
|
|
1132
|
+
* @param {boolean} [options.binary] - Write binary data in Level 1 PostScript. By default,
|
|
1106
1133
|
* pdftops writes hex-encoded data in Level 1 PostScript. Binary data is non-standard in Level 1
|
|
1107
1134
|
* PostScript but reduces the file size and can be useful when Level 1 PostScript is required
|
|
1108
1135
|
* only for its restricted use of PostScript operators.
|
|
1109
|
-
* @param {string
|
|
1136
|
+
* @param {string} [options.defaultCmykProfile] - If Poppler is compiled with colour management support, this option
|
|
1110
1137
|
* sets the DefaultCMYK color space to the ICC profile stored in the display profile file passed.
|
|
1111
|
-
* @param {string
|
|
1138
|
+
* @param {string} [options.defaultGrayProfile] - If Poppler is compiled with colour management support, this option
|
|
1112
1139
|
* sets the DefaultGray color space to the ICC profile stored in the display profile file passed.
|
|
1113
|
-
* @param {string
|
|
1140
|
+
* @param {string} [options.defaultRgbProfile] - If Poppler is compiled with colour management support, this option
|
|
1114
1141
|
* sets the DefaultRGB color space to the ICC profile stored in the display profile file passed.
|
|
1115
|
-
* @param {boolean
|
|
1142
|
+
* @param {boolean} [options.duplex] - Set the Duplex pagedevice entry in the PostScript file.
|
|
1116
1143
|
* This tells duplex-capable printers to enable duplexing.
|
|
1117
|
-
* @param {boolean
|
|
1144
|
+
* @param {boolean} [options.epsFile] - Generate an EPS file. An EPS file contains a single image,
|
|
1118
1145
|
* so if you use this option with a multi-page PDF file, you must use `options.firstPageToConvert` and
|
|
1119
1146
|
* `options.lastPageToConvert` to specify a single page.
|
|
1120
1147
|
* The page size options (originalPageSizes, paperSize, paperWidth, paperHeight) can not be used
|
|
1121
1148
|
* with this option.
|
|
1122
|
-
* @param {boolean
|
|
1149
|
+
* @param {boolean} [options.fillPage] - Expand PDF pages smaller than the paper to fill the
|
|
1123
1150
|
* paper. By default, these pages are not scaled.
|
|
1124
|
-
* @param {number
|
|
1125
|
-
* @param {number
|
|
1151
|
+
* @param {number} [options.firstPageToConvert] - Specifies the first page to convert.
|
|
1152
|
+
* @param {number} [options.form] - Generate PostScript form which can be imported by software
|
|
1126
1153
|
* that understands forms.
|
|
1127
1154
|
* A form contains a single page, so if you use this option with a multi-page PDF file,
|
|
1128
1155
|
* you must use `options.firstPageToConvert` and `options.lastPageToConvert` to specify a single page.
|
|
1129
1156
|
* The `options.level1` option cannot be used with `options.form`.
|
|
1130
1157
|
* No more than one of the mode options (`options.epsFile`, `options.form`) may be given.
|
|
1131
|
-
* @param {number
|
|
1132
|
-
* @param {boolean
|
|
1158
|
+
* @param {number} [options.lastPageToConvert] - Specifies the last page to convert.
|
|
1159
|
+
* @param {boolean} [options.level1] - Generate Level 1 PostScript. The resulting PostScript
|
|
1133
1160
|
* files will be significantly larger (if they contain images), but will print on Level 1 printers.
|
|
1134
1161
|
* This also converts all images to black and white.
|
|
1135
|
-
* @param {boolean
|
|
1162
|
+
* @param {boolean} [options.level1Sep] - Generate Level 1 separable PostScript.
|
|
1136
1163
|
* All colors are converted to CMYK. Images are written with separate stream data for the four components.
|
|
1137
|
-
* @param {boolean
|
|
1164
|
+
* @param {boolean} [options.level2] - Generate Level 2 PostScript.
|
|
1138
1165
|
* Level 2 supports color images and image compression. This is the default setting.
|
|
1139
|
-
* @param {boolean
|
|
1166
|
+
* @param {boolean} [options.level2Sep] - Generate Level 2 separable PostScript. All colors are
|
|
1140
1167
|
* converted to CMYK. The PostScript separation convention operators are used to handle custom (spot) colors.
|
|
1141
|
-
* @param {boolean
|
|
1168
|
+
* @param {boolean} [options.level3] - Generate Level 3 PostScript.
|
|
1142
1169
|
* This enables all Level 2 featuresplus CID font embedding.
|
|
1143
|
-
* @param {boolean
|
|
1170
|
+
* @param {boolean} [options.level3Sep] - Generate Level 3 separable PostScript.
|
|
1144
1171
|
* The separation handling is the same as for `options.level2Sep`.
|
|
1145
|
-
* @param {boolean
|
|
1172
|
+
* @param {boolean} [options.noEmbedCIDFonts] - By default, any CID PostScript fonts which are
|
|
1146
1173
|
* embedded in the PDF file are copied into the PostScript file. This option disables that embedding.
|
|
1147
1174
|
* No attempt is made to substitute for non-embedded CID PostScript fonts.
|
|
1148
|
-
* @param {boolean
|
|
1175
|
+
* @param {boolean} [options.noEmbedCIDTrueTypeFonts] - By default, any CID TrueType fonts which are
|
|
1149
1176
|
* embedded in the PDF file are copied into the PostScript file. This option disables that embedding.
|
|
1150
1177
|
* No attempt is made to substitute for non-embedded CID TrueType fonts.
|
|
1151
|
-
* @param {boolean
|
|
1178
|
+
* @param {boolean} [options.noEmbedTrueTypeFonts] - By default, any TrueType fonts which are embedded
|
|
1152
1179
|
* in the PDF file are copied into the PostScript file. This option causes pdfToPs to substitute base fonts instead.
|
|
1153
1180
|
* Embedded fonts make PostScript files larger, but may be necessary for readable output.
|
|
1154
1181
|
* Also, some PostScript interpreters do not have TrueType rasterizers.
|
|
1155
|
-
* @param {boolean
|
|
1182
|
+
* @param {boolean} [options.noEmbedType1Fonts] - By default, any Type 1 fonts which are embedded in the PDF file
|
|
1156
1183
|
* are copied into the PostScript file. This option causes pdfToPs to substitute base fonts instead.
|
|
1157
1184
|
* Embedded fonts make PostScript files larger, but may be necessary for readable output.
|
|
1158
|
-
* @param {boolean
|
|
1185
|
+
* @param {boolean} [options.noCenter] - By default, PDF pages smaller than the paper
|
|
1159
1186
|
* (after any scaling) are centered on the paper. This option causes them to be aligned to
|
|
1160
1187
|
* the lower-left corner of the paper instead.
|
|
1161
|
-
* @param {boolean
|
|
1188
|
+
* @param {boolean} [options.noCrop] - By default, printing output is cropped to the CropBox
|
|
1162
1189
|
* specified in the PDF file. This option disables cropping.
|
|
1163
|
-
* @param {boolean
|
|
1190
|
+
* @param {boolean} [options.noShrink] - Do not scale PDF pages which are larger than the paper.
|
|
1164
1191
|
* By default, pages larger than the paper are shrunk to fit.
|
|
1165
|
-
* @param {boolean
|
|
1166
|
-
* @param {boolean
|
|
1192
|
+
* @param {boolean} [options.opi] - Generate OPI comments for all images and forms which have OPI information.
|
|
1193
|
+
* @param {boolean} [options.optimizecolorspace] - By default, bitmap images in the PDF pass through to the
|
|
1167
1194
|
* output PostScript in their original color space, which produces predictable results.
|
|
1168
1195
|
* This option converts RGB and CMYK images into Gray images if every pixel of the image has equal components.
|
|
1169
1196
|
* This can fix problems when doing color separations of PDFs that contain embedded black and
|
|
1170
1197
|
* white images encoded as RGB.
|
|
1171
|
-
* @param {boolean
|
|
1198
|
+
* @param {boolean} [options.originalPageSizes] - Set the paper size of each page to match
|
|
1172
1199
|
* the size specified in the PDF file.
|
|
1173
|
-
* @param {boolean
|
|
1174
|
-
* @param {string
|
|
1175
|
-
* @param {number
|
|
1176
|
-
* @param {('
|
|
1177
|
-
* or `
|
|
1200
|
+
* @param {boolean} [options.overprint] - Enable overprinting.
|
|
1201
|
+
* @param {string} [options.ownerPassword] - Owner password (for encrypted files).
|
|
1202
|
+
* @param {number} [options.paperHeight] - Set the paper height, in points.
|
|
1203
|
+
* @param {('A3'|'A4'|'legal'|'letter'|'match')} [options.paperSize] - Set the paper size to one of `A3`, `A4`,
|
|
1204
|
+
* `legal`, or `letter`. This can also be set to `match`, which will set the paper size
|
|
1178
1205
|
* of each page to match the size specified in the PDF file. If none of the paperSize,
|
|
1179
1206
|
* paperWidth, or paperHeight options are specified the default is to match the paper size.
|
|
1180
|
-
* @param {number
|
|
1181
|
-
* @param {boolean
|
|
1207
|
+
* @param {number} [options.paperWidth] - Set the paper width, in points.
|
|
1208
|
+
* @param {boolean} [options.passfonts] - By default, references to non-embedded 8-bit fonts
|
|
1182
1209
|
* in the PDF file are substituted with the closest `Helvetica`, `Times-Roman`, or `Courier` font.
|
|
1183
1210
|
* This option passes references to non-embedded fonts through to the PostScript file.
|
|
1184
|
-
* @param {boolean
|
|
1185
|
-
* @param {boolean
|
|
1186
|
-
* @param {('CMYK8'|'MONO8'|'RGB8')
|
|
1211
|
+
* @param {boolean} [options.preload] - Preload images and forms.
|
|
1212
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version information.
|
|
1213
|
+
* @param {('CMYK8'|'MONO8'|'RGB8')} [options.processColorFormat] - Sets the process color format as it is used
|
|
1187
1214
|
* during rasterization and transparency reduction.
|
|
1188
1215
|
*
|
|
1189
1216
|
* The default depends on the other settings: For `options.level1` the default is MONO8; for `options.level1Sep`,
|
|
1190
1217
|
* `options.level2Sep`, `options.level3Sep`, or `options.overprint` the default is CMYK8; in all other
|
|
1191
1218
|
* cases RGB8 is the default.
|
|
1192
1219
|
* If `option.processColorProfile` is set then `options.processColorFormat` is inferred from the specified ICC profile.
|
|
1193
|
-
* @param {string
|
|
1220
|
+
* @param {string} [options.processColorProfile] - Sets the ICC profile that is assumed during
|
|
1194
1221
|
* rasterization and transparency reduction.
|
|
1195
|
-
* @param {boolean
|
|
1196
|
-
* @param {('always'|'never'|'whenneeded')
|
|
1222
|
+
* @param {boolean} [options.quiet] - Do not print any messages or errors.
|
|
1223
|
+
* @param {('always'|'never'|'whenneeded')} [options.rasterize] - By default, pdfToPs rasterizes pages as needed,
|
|
1197
1224
|
* for example, if they contain transparencies. To force rasterization, set `rasterize` to `always`.
|
|
1198
1225
|
* Use this to eliminate fonts.
|
|
1199
1226
|
* To prevent rasterization, set `rasterize` to `never`.
|
|
1200
1227
|
* This may produce files that display incorrectly.
|
|
1201
|
-
* @param {number
|
|
1228
|
+
* @param {number} [options.resolutionXYAxis] - Specifies the X and Y resolution, in pixels per
|
|
1202
1229
|
* inch of image files (or rasterized regions in vector output). The default is 300 PPI.
|
|
1203
|
-
* @param {string
|
|
1230
|
+
* @param {string} [options.userPassword] - User password (for encrypted files).
|
|
1204
1231
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
1205
1232
|
*/
|
|
1206
1233
|
async pdfToPs(file, outputFile, options = {}) {
|
|
@@ -1265,7 +1292,7 @@ class Poppler {
|
|
|
1265
1292
|
processColorFormat: { arg: "-processcolorformat", type: "string" },
|
|
1266
1293
|
quiet: { arg: "-q", type: "boolean" },
|
|
1267
1294
|
rasterize: {
|
|
1268
|
-
|
|
1295
|
+
arg: "-rasterize",
|
|
1269
1296
|
type: "string",
|
|
1270
1297
|
minVersion: "0.90.0",
|
|
1271
1298
|
},
|
|
@@ -1275,10 +1302,11 @@ class Poppler {
|
|
|
1275
1302
|
|
|
1276
1303
|
try {
|
|
1277
1304
|
const { stderr } = await execFileAsync(
|
|
1278
|
-
|
|
1305
|
+
joinSafe(this.popplerPath, "pdftops"),
|
|
1279
1306
|
["-v"]
|
|
1280
1307
|
);
|
|
1281
1308
|
|
|
1309
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
1282
1310
|
const versionInfo = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(stderr)[1];
|
|
1283
1311
|
|
|
1284
1312
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
@@ -1297,7 +1325,7 @@ class Poppler {
|
|
|
1297
1325
|
}
|
|
1298
1326
|
|
|
1299
1327
|
const child = spawn(
|
|
1300
|
-
|
|
1328
|
+
joinSafe(this.popplerPath, "pdftops"),
|
|
1301
1329
|
args
|
|
1302
1330
|
);
|
|
1303
1331
|
|
|
@@ -1318,6 +1346,7 @@ class Poppler {
|
|
|
1318
1346
|
});
|
|
1319
1347
|
|
|
1320
1348
|
child.on("close", (code) => {
|
|
1349
|
+
/* istanbul ignore else */
|
|
1321
1350
|
if (stdOut !== "") {
|
|
1322
1351
|
resolve(stdOut.trim());
|
|
1323
1352
|
} else if (code === 0) {
|
|
@@ -1325,8 +1354,11 @@ class Poppler {
|
|
|
1325
1354
|
} else if (stdErr !== "") {
|
|
1326
1355
|
reject(new Error(stdErr.trim()));
|
|
1327
1356
|
} else {
|
|
1328
|
-
|
|
1329
|
-
|
|
1357
|
+
reject(
|
|
1358
|
+
new Error(
|
|
1359
|
+
code ? errorMessages[code] : errorMessages.unk
|
|
1360
|
+
)
|
|
1361
|
+
);
|
|
1330
1362
|
}
|
|
1331
1363
|
});
|
|
1332
1364
|
});
|
|
@@ -1338,49 +1370,49 @@ class Poppler {
|
|
|
1338
1370
|
/**
|
|
1339
1371
|
* @author Frazer Smith
|
|
1340
1372
|
* @description Converts a PDF file to TXT.
|
|
1341
|
-
* @param {Buffer|
|
|
1342
|
-
* @param {string
|
|
1373
|
+
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
1374
|
+
* @param {string} [outputFile] - Filepath of the file to output the results to.
|
|
1343
1375
|
* If `undefined` then will write output to stdout.
|
|
1344
|
-
* @param {object
|
|
1345
|
-
* @param {boolean
|
|
1376
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
1377
|
+
* @param {boolean} [options.boundingBoxXhtml] - Generate an XHTML file containing bounding
|
|
1346
1378
|
* box information for each word in the file.
|
|
1347
|
-
* @param {boolean
|
|
1379
|
+
* @param {boolean} [options.boundingBoxXhtmlLayout] - Generate an XHTML file containing
|
|
1348
1380
|
* bounding box information for each block, line, and word in the file.
|
|
1349
|
-
* @param {boolean
|
|
1381
|
+
* @param {boolean} [options.cropBox] - Use the crop box rather than the media box with
|
|
1350
1382
|
* `options.boundingBoxXhtml` and `options.boundingBoxXhtmlLayout`
|
|
1351
|
-
* @param {number
|
|
1383
|
+
* @param {number} [options.cropHeight] - Specifies the height of crop area in pixels
|
|
1352
1384
|
* (image output) or points (vector output).
|
|
1353
|
-
* @param {number
|
|
1385
|
+
* @param {number} [options.cropWidth] - Specifies the width of crop area in pixels
|
|
1354
1386
|
* (image output) or points (vector output).
|
|
1355
|
-
* @param {number
|
|
1387
|
+
* @param {number} [options.cropXAxis] - Specifies the x-coordinate of the crop area top left
|
|
1356
1388
|
* corner in pixels (image output) or points (vector output).
|
|
1357
|
-
* @param {number
|
|
1389
|
+
* @param {number} [options.cropYAxis] - Specifies the y-coordinate of the crop area top left
|
|
1358
1390
|
* corner in pixels (image output) or points (vector output).
|
|
1359
|
-
* @param {('
|
|
1360
|
-
* text output:
|
|
1361
|
-
* @param {number
|
|
1362
|
-
* @param {number
|
|
1391
|
+
* @param {('dos'|'mac'|'unix')} [options.eolConvention] - Sets the end-of-line convention to use for
|
|
1392
|
+
* text output: dos; mac; unix.
|
|
1393
|
+
* @param {number} [options.firstPageToConvert] - Specifies the first page to convert.
|
|
1394
|
+
* @param {number} [options.fixedWidthLayout] - Assume fixed-pitch (or tabular) text, with the
|
|
1363
1395
|
* specified character width (in points). This forces physical layout mode.
|
|
1364
|
-
* @param {boolean
|
|
1396
|
+
* @param {boolean} [options.generateHtmlMetaFile] - Generate simple HTML file, including the
|
|
1365
1397
|
* meta information. This simply wraps the text in `<pre>` and `</pre>` and prepends the meta headers.
|
|
1366
|
-
* @param {boolean
|
|
1398
|
+
* @param {boolean} [options.generateTsvFile] - Generate a TSV file containing the bounding box
|
|
1367
1399
|
* information for each block, line, and word in the file.
|
|
1368
|
-
* @param {number
|
|
1369
|
-
* @param {boolean
|
|
1370
|
-
* @param {boolean
|
|
1400
|
+
* @param {number} [options.lastPageToConvert] - Specifies the last page to convert.
|
|
1401
|
+
* @param {boolean} [options.listEncodingOptions] - List the available encodings.
|
|
1402
|
+
* @param {boolean} [options.maintainLayout] - Maintain (as best as possible) the original physical
|
|
1371
1403
|
* layout of the text. The default is to undo physical layout (columns, hyphenation, etc.) and
|
|
1372
1404
|
* output the text in reading order.
|
|
1373
|
-
* @param {boolean
|
|
1374
|
-
* @param {boolean
|
|
1405
|
+
* @param {boolean} [options.noDiagonalText] - Discard diagonal text.
|
|
1406
|
+
* @param {boolean} [options.noPageBreaks] - Do not insert page breaks (form feed characters)
|
|
1375
1407
|
* between pages.
|
|
1376
|
-
* @param {string
|
|
1408
|
+
* @param {string} [options.outputEncoding] - Sets the encoding to use for text output.
|
|
1377
1409
|
* This defaults to `UTF-8`.
|
|
1378
|
-
* @param {string
|
|
1379
|
-
* @param {boolean
|
|
1380
|
-
* @param {boolean
|
|
1381
|
-
* @param {boolean
|
|
1410
|
+
* @param {string} [options.ownerPassword] - Owner password (for encrypted files).
|
|
1411
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version information.
|
|
1412
|
+
* @param {boolean} [options.quiet] - Do not print any messages or errors.
|
|
1413
|
+
* @param {boolean} [options.rawLayout] - Keep the text in content stream order. This is a
|
|
1382
1414
|
* hack which often undoes column formatting, etc. Use of raw mode is no longer recommended.
|
|
1383
|
-
* @param {string
|
|
1415
|
+
* @param {string} [options.userPassword] - User password (for encrypted files).
|
|
1384
1416
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
1385
1417
|
*/
|
|
1386
1418
|
async pdfToText(file, outputFile, options = {}) {
|
|
@@ -1424,10 +1456,11 @@ class Poppler {
|
|
|
1424
1456
|
|
|
1425
1457
|
try {
|
|
1426
1458
|
const { stderr } = await execFileAsync(
|
|
1427
|
-
|
|
1459
|
+
joinSafe(this.popplerPath, "pdftotext"),
|
|
1428
1460
|
["-v"]
|
|
1429
1461
|
);
|
|
1430
1462
|
|
|
1463
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
1431
1464
|
const versionInfo = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(stderr)[1];
|
|
1432
1465
|
|
|
1433
1466
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
@@ -1446,7 +1479,7 @@ class Poppler {
|
|
|
1446
1479
|
}
|
|
1447
1480
|
|
|
1448
1481
|
const child = spawn(
|
|
1449
|
-
|
|
1482
|
+
joinSafe(this.popplerPath, "pdftotext"),
|
|
1450
1483
|
args
|
|
1451
1484
|
);
|
|
1452
1485
|
|
|
@@ -1467,6 +1500,7 @@ class Poppler {
|
|
|
1467
1500
|
});
|
|
1468
1501
|
|
|
1469
1502
|
child.on("close", (code) => {
|
|
1503
|
+
/* istanbul ignore else */
|
|
1470
1504
|
if (stdOut !== "") {
|
|
1471
1505
|
resolve(stdOut.trim());
|
|
1472
1506
|
} else if (code === 0) {
|
|
@@ -1474,8 +1508,11 @@ class Poppler {
|
|
|
1474
1508
|
} else if (stdErr !== "") {
|
|
1475
1509
|
reject(new Error(stdErr.trim()));
|
|
1476
1510
|
} else {
|
|
1477
|
-
|
|
1478
|
-
|
|
1511
|
+
reject(
|
|
1512
|
+
new Error(
|
|
1513
|
+
code ? errorMessages[code] : errorMessages.unk
|
|
1514
|
+
)
|
|
1515
|
+
);
|
|
1479
1516
|
}
|
|
1480
1517
|
});
|
|
1481
1518
|
});
|
|
@@ -1488,11 +1525,11 @@ class Poppler {
|
|
|
1488
1525
|
* @author Frazer Smith
|
|
1489
1526
|
* @description Merges several PDF files in order of their occurrence in the files array to
|
|
1490
1527
|
* one PDF result file.
|
|
1491
|
-
* @param {
|
|
1528
|
+
* @param {string[]} files - Filepaths of the PDF files to merge.
|
|
1492
1529
|
* An entire directory of PDF files can be merged like so: `path/to/directory/*.pdf`.
|
|
1493
1530
|
* @param {string} outputFile - Filepath of the file to output the resulting merged PDF to.
|
|
1494
|
-
* @param {object
|
|
1495
|
-
* @param {boolean
|
|
1531
|
+
* @param {object} [options] - Object containing options to pass to binary.
|
|
1532
|
+
* @param {boolean} [options.printVersionInfo] - Print copyright and version information.
|
|
1496
1533
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
1497
1534
|
*/
|
|
1498
1535
|
async pdfUnite(files, outputFile, options = {}) {
|
|
@@ -1502,10 +1539,11 @@ class Poppler {
|
|
|
1502
1539
|
|
|
1503
1540
|
try {
|
|
1504
1541
|
const { stderr } = await execFileAsync(
|
|
1505
|
-
|
|
1542
|
+
joinSafe(this.popplerPath, "pdfunite"),
|
|
1506
1543
|
["-v"]
|
|
1507
1544
|
);
|
|
1508
1545
|
|
|
1546
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
1509
1547
|
const versionInfo = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(stderr)[1];
|
|
1510
1548
|
|
|
1511
1549
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
@@ -1515,7 +1553,7 @@ class Poppler {
|
|
|
1515
1553
|
args.push(outputFile);
|
|
1516
1554
|
|
|
1517
1555
|
const { stdout } = await execFileAsync(
|
|
1518
|
-
|
|
1556
|
+
joinSafe(this.popplerPath, "pdfunite"),
|
|
1519
1557
|
args
|
|
1520
1558
|
);
|
|
1521
1559
|
return Promise.resolve(stdout);
|