node-poppler 7.2.4 → 8.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 +2 -2
- package/package.json +3 -3
- package/src/index.js +87 -43
- package/types/index.d.ts +263 -239
package/README.md
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
[](https://coveralls.io/github/Fdawgs/node-poppler?branch=main)
|
|
7
7
|
[](https://github.com/prettier/prettier)
|
|
8
8
|
|
|
9
|
-
> Asynchronous
|
|
9
|
+
> Asynchronous Node.js wrapper for the Poppler PDF rendering library
|
|
10
10
|
|
|
11
11
|
## Overview
|
|
12
12
|
|
|
13
13
|
[Poppler](https://poppler.freedesktop.org/) is a PDF rendering library that also includes a collection of utility binaries, which allows for the manipulation and extraction of data from PDF documents such as converting PDF files to HTML, TXT, or PostScript.
|
|
14
14
|
|
|
15
|
-
The `node-poppler` module provides an asynchronous
|
|
15
|
+
The `node-poppler` module provides an asynchronous Node.js wrapper around said utility binaries for easier use.
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-poppler",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Asynchronous
|
|
3
|
+
"version": "8.0.0",
|
|
4
|
+
"description": "Asynchronous Node.js wrapper for the Poppler PDF rendering library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"async",
|
|
7
7
|
"attach",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"author": "Frazer Smith <frazer.dev@icloud.com>",
|
|
48
48
|
"funding": "https://github.com/sponsors/Fdawgs",
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
50
|
+
"node": ">=20"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"camelcase": "^6.3.0",
|
package/src/index.js
CHANGED
|
@@ -22,12 +22,24 @@ const errorMessages = {
|
|
|
22
22
|
const popplerVersionRegex = /(\d{1,2}\.\d{1,2}\.\d{1,2})/u;
|
|
23
23
|
const pdfInfoFileSizesRegex = /(File\s+size:\s+)0(\s+)bytes/u;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {object} OptionDetails
|
|
27
|
+
* @property {string} arg The argument to pass to the binary.
|
|
28
|
+
* @property {('boolean'|'number'|'string')} type The type of the option.
|
|
29
|
+
* @property {string} [minVersion] The minimum version of the binary that supports this option.
|
|
30
|
+
* @property {string} [maxVersion] The maximum version of the binary that supports this option (optional).
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {Record<string, OptionDetails>} PopplerAcceptedOptions
|
|
35
|
+
*/
|
|
36
|
+
|
|
25
37
|
/**
|
|
26
38
|
* @author Frazer Smith
|
|
27
39
|
* @description Checks each option provided is valid, of the correct type, and can be used by specified
|
|
28
40
|
* version of binary.
|
|
29
41
|
* @ignore
|
|
30
|
-
* @param {
|
|
42
|
+
* @param {PopplerAcceptedOptions} acceptedOptions - Object containing accepted options.
|
|
31
43
|
* @param {Record<string, any>} options - Object containing options to pass to binary.
|
|
32
44
|
* @param {string} [version] - Version of binary.
|
|
33
45
|
* @returns {string[]} Array of CLI arguments.
|
|
@@ -38,7 +50,10 @@ function parseOptions(acceptedOptions, options, version) {
|
|
|
38
50
|
const args = [];
|
|
39
51
|
/** @type {string[]} */
|
|
40
52
|
const invalidArgs = [];
|
|
41
|
-
|
|
53
|
+
const keys = Object.keys(options);
|
|
54
|
+
const keysLength = keys.length;
|
|
55
|
+
for (let i = 0; i < keysLength; i += 1) {
|
|
56
|
+
const key = keys[i];
|
|
42
57
|
if (Object.hasOwn(acceptedOptions, key)) {
|
|
43
58
|
const option = options[key];
|
|
44
59
|
const acceptedOption = acceptedOptions[key];
|
|
@@ -85,6 +100,8 @@ function parseOptions(acceptedOptions, options, version) {
|
|
|
85
100
|
}
|
|
86
101
|
|
|
87
102
|
class Poppler {
|
|
103
|
+
#popplerPath;
|
|
104
|
+
|
|
88
105
|
/**
|
|
89
106
|
* @param {string} [binPath] - Path of poppler-utils binaries.
|
|
90
107
|
* If not provided, the constructor will attempt to find the Poppler `pdfinfo` binary
|
|
@@ -93,12 +110,12 @@ class Poppler {
|
|
|
93
110
|
* if a local installation is not found.
|
|
94
111
|
*/
|
|
95
112
|
constructor(binPath) {
|
|
96
|
-
this
|
|
113
|
+
this.#popplerPath = "";
|
|
97
114
|
|
|
98
115
|
/* istanbul ignore else: requires specific OS */
|
|
99
116
|
if (binPath) {
|
|
100
117
|
/** @type {string|undefined} */
|
|
101
|
-
this
|
|
118
|
+
this.#popplerPath = binPath;
|
|
102
119
|
} else {
|
|
103
120
|
const { platform } = process;
|
|
104
121
|
|
|
@@ -108,10 +125,10 @@ class Poppler {
|
|
|
108
125
|
const popplerPath = /(.+)pdfinfo/u.exec(which)?.[1];
|
|
109
126
|
|
|
110
127
|
if (popplerPath) {
|
|
111
|
-
this
|
|
128
|
+
this.#popplerPath = popplerPath;
|
|
112
129
|
}
|
|
113
130
|
if (platform === "win32" && !popplerPath) {
|
|
114
|
-
this
|
|
131
|
+
this.#popplerPath = pathResolve(
|
|
115
132
|
__dirname,
|
|
116
133
|
"lib",
|
|
117
134
|
"win32",
|
|
@@ -123,12 +140,20 @@ class Poppler {
|
|
|
123
140
|
}
|
|
124
141
|
|
|
125
142
|
/* istanbul ignore next: unable to test due to https://github.com/jestjs/jest/pull/14297 */
|
|
126
|
-
if (!this
|
|
143
|
+
if (!this.#popplerPath) {
|
|
127
144
|
throw new Error(
|
|
128
145
|
`Unable to find ${process.platform} Poppler binaries, please pass the installation directory as a parameter to the Poppler instance.`
|
|
129
146
|
);
|
|
130
147
|
}
|
|
131
|
-
this
|
|
148
|
+
this.#popplerPath = normalize(this.#popplerPath);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @description Returns the path of the Poppler binaries.
|
|
153
|
+
* @returns {string} Path of Poppler binaries.
|
|
154
|
+
*/
|
|
155
|
+
get path() {
|
|
156
|
+
return this.#popplerPath;
|
|
132
157
|
}
|
|
133
158
|
|
|
134
159
|
/**
|
|
@@ -143,6 +168,7 @@ class Poppler {
|
|
|
143
168
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
144
169
|
*/
|
|
145
170
|
async pdfAttach(file, fileToAttach, outputFile, options = {}) {
|
|
171
|
+
/** @type {PopplerAcceptedOptions} */
|
|
146
172
|
const acceptedOptions = {
|
|
147
173
|
printVersionInfo: { arg: "-v", type: "boolean" },
|
|
148
174
|
replace: { arg: "-replace", type: "boolean" },
|
|
@@ -153,7 +179,7 @@ class Poppler {
|
|
|
153
179
|
args.push(file, fileToAttach, outputFile);
|
|
154
180
|
|
|
155
181
|
const { stdout } = await execFileAsync(
|
|
156
|
-
pathResolve(this
|
|
182
|
+
pathResolve(this.#popplerPath, "pdfattach"),
|
|
157
183
|
args
|
|
158
184
|
);
|
|
159
185
|
return Promise.resolve(stdout);
|
|
@@ -189,6 +215,7 @@ class Poppler {
|
|
|
189
215
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
190
216
|
*/
|
|
191
217
|
async pdfDetach(file, options = {}) {
|
|
218
|
+
/** @type {PopplerAcceptedOptions} */
|
|
192
219
|
const acceptedOptions = {
|
|
193
220
|
listEmbedded: { arg: "-list", type: "boolean" },
|
|
194
221
|
outputEncoding: { arg: "-enc", type: "string" },
|
|
@@ -210,7 +237,7 @@ class Poppler {
|
|
|
210
237
|
args.push(file);
|
|
211
238
|
|
|
212
239
|
const { stdout } = await execFileAsync(
|
|
213
|
-
pathResolve(this
|
|
240
|
+
pathResolve(this.#popplerPath, "pdfdetach"),
|
|
214
241
|
args
|
|
215
242
|
);
|
|
216
243
|
return Promise.resolve(stdout);
|
|
@@ -222,7 +249,7 @@ class Poppler {
|
|
|
222
249
|
/**
|
|
223
250
|
* @author Frazer Smith
|
|
224
251
|
* @description Lists the fonts used in a PDF file along with various information for each font.
|
|
225
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
252
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
226
253
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
227
254
|
* @param {number} [options.firstPageToExamine] - Specifies the first page to examine.
|
|
228
255
|
* @param {number} [options.lastPageToExamine] - Specifies the last page to examine.
|
|
@@ -234,6 +261,7 @@ class Poppler {
|
|
|
234
261
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
235
262
|
*/
|
|
236
263
|
async pdfFonts(file, options = {}) {
|
|
264
|
+
/** @type {PopplerAcceptedOptions} */
|
|
237
265
|
const acceptedOptions = {
|
|
238
266
|
firstPageToExamine: { arg: "-f", type: "number" },
|
|
239
267
|
lastPageToExamine: { arg: "-l", type: "number" },
|
|
@@ -245,7 +273,7 @@ class Poppler {
|
|
|
245
273
|
|
|
246
274
|
try {
|
|
247
275
|
const { stderr } = await execFileAsync(
|
|
248
|
-
pathResolve(this
|
|
276
|
+
pathResolve(this.#popplerPath, "pdffonts"),
|
|
249
277
|
["-v"]
|
|
250
278
|
);
|
|
251
279
|
|
|
@@ -258,7 +286,7 @@ class Poppler {
|
|
|
258
286
|
args.push(Buffer.isBuffer(file) ? "-" : file);
|
|
259
287
|
|
|
260
288
|
const child = spawn(
|
|
261
|
-
pathResolve(this
|
|
289
|
+
pathResolve(this.#popplerPath, "pdffonts"),
|
|
262
290
|
args
|
|
263
291
|
);
|
|
264
292
|
|
|
@@ -289,6 +317,7 @@ class Poppler {
|
|
|
289
317
|
} else {
|
|
290
318
|
reject(
|
|
291
319
|
new Error(
|
|
320
|
+
// @ts-ignore: Second operand used if code is not in errorMessages
|
|
292
321
|
errorMessages[code] ||
|
|
293
322
|
`pdffonts ${args.join(
|
|
294
323
|
" "
|
|
@@ -306,7 +335,7 @@ class Poppler {
|
|
|
306
335
|
/**
|
|
307
336
|
* @author Frazer Smith
|
|
308
337
|
* @description Saves images from a PDF file as PPM, PBM, PNG, TIFF, JPEG, JPEG2000, or JBIG2 files.
|
|
309
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
338
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
310
339
|
* @param {string} [outputPrefix] - Filename prefix of output files.
|
|
311
340
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
312
341
|
* @param {boolean} [options.allFiles] - Write JPEG, JPEG2000, JBIG2, and CCITT images in their native format.
|
|
@@ -328,6 +357,7 @@ class Poppler {
|
|
|
328
357
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
329
358
|
*/
|
|
330
359
|
async pdfImages(file, outputPrefix, options = {}) {
|
|
360
|
+
/** @type {PopplerAcceptedOptions} */
|
|
331
361
|
const acceptedOptions = {
|
|
332
362
|
allFiles: { arg: "-all", type: "boolean" },
|
|
333
363
|
ccittFile: { arg: "-ccitt", type: "boolean" },
|
|
@@ -346,7 +376,7 @@ class Poppler {
|
|
|
346
376
|
|
|
347
377
|
try {
|
|
348
378
|
const { stderr } = await execFileAsync(
|
|
349
|
-
pathResolve(this
|
|
379
|
+
pathResolve(this.#popplerPath, "pdfimages"),
|
|
350
380
|
["-v"]
|
|
351
381
|
);
|
|
352
382
|
|
|
@@ -363,7 +393,7 @@ class Poppler {
|
|
|
363
393
|
}
|
|
364
394
|
|
|
365
395
|
const child = spawn(
|
|
366
|
-
pathResolve(this
|
|
396
|
+
pathResolve(this.#popplerPath, "pdfimages"),
|
|
367
397
|
args
|
|
368
398
|
);
|
|
369
399
|
|
|
@@ -394,6 +424,7 @@ class Poppler {
|
|
|
394
424
|
} else {
|
|
395
425
|
reject(
|
|
396
426
|
new Error(
|
|
427
|
+
// @ts-ignore: Second operand used if code is not in errorMessages
|
|
397
428
|
errorMessages[code] ||
|
|
398
429
|
`pdfimages ${args.join(
|
|
399
430
|
" "
|
|
@@ -411,7 +442,7 @@ class Poppler {
|
|
|
411
442
|
/**
|
|
412
443
|
* @author Frazer Smith
|
|
413
444
|
* @description Prints the contents of the `Info` dictionary from a PDF file.
|
|
414
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
445
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
415
446
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
416
447
|
* @param {number} [options.firstPageToConvert] - First page to print.
|
|
417
448
|
* @param {number} [options.lastPageToConvert] - Last page to print.
|
|
@@ -443,6 +474,7 @@ class Poppler {
|
|
|
443
474
|
* `options.printAsJson` is `true`, or rejects with an `Error` object.
|
|
444
475
|
*/
|
|
445
476
|
async pdfInfo(file, options = {}) {
|
|
477
|
+
/** @type {PopplerAcceptedOptions} */
|
|
446
478
|
const acceptedOptions = {
|
|
447
479
|
firstPageToConvert: { arg: "-f", type: "number" },
|
|
448
480
|
lastPageToConvert: { arg: "-l", type: "number" },
|
|
@@ -465,7 +497,7 @@ class Poppler {
|
|
|
465
497
|
|
|
466
498
|
try {
|
|
467
499
|
const { stderr } = await execFileAsync(
|
|
468
|
-
pathResolve(this
|
|
500
|
+
pathResolve(this.#popplerPath, "pdfinfo"),
|
|
469
501
|
["-v"]
|
|
470
502
|
);
|
|
471
503
|
|
|
@@ -490,7 +522,7 @@ class Poppler {
|
|
|
490
522
|
}
|
|
491
523
|
|
|
492
524
|
const child = spawn(
|
|
493
|
-
pathResolve(this
|
|
525
|
+
pathResolve(this.#popplerPath, "pdfinfo"),
|
|
494
526
|
args
|
|
495
527
|
);
|
|
496
528
|
|
|
@@ -526,13 +558,16 @@ class Poppler {
|
|
|
526
558
|
*/
|
|
527
559
|
if (options.printAsJson === true) {
|
|
528
560
|
const info = {};
|
|
529
|
-
stdOut.split("\n")
|
|
561
|
+
const stdOutLines = stdOut.split("\n");
|
|
562
|
+
const stdOutLinesLength = stdOutLines.length;
|
|
563
|
+
for (let i = 0; i < stdOutLinesLength; i += 1) {
|
|
564
|
+
const line = stdOutLines[i];
|
|
530
565
|
const lines = line.split(": ");
|
|
531
566
|
if (lines.length > 1) {
|
|
532
567
|
// @ts-ignore: creating dynamic object keys
|
|
533
568
|
info[camelCase(lines[0])] = lines[1].trim();
|
|
534
569
|
}
|
|
535
|
-
}
|
|
570
|
+
}
|
|
536
571
|
resolve(info);
|
|
537
572
|
} else {
|
|
538
573
|
resolve(stdOut.trim());
|
|
@@ -544,6 +579,7 @@ class Poppler {
|
|
|
544
579
|
} else {
|
|
545
580
|
reject(
|
|
546
581
|
new Error(
|
|
582
|
+
// @ts-ignore: Second operand used if code is not in errorMessages
|
|
547
583
|
errorMessages[code] ||
|
|
548
584
|
`pdfinfo ${args.join(
|
|
549
585
|
" "
|
|
@@ -576,6 +612,7 @@ class Poppler {
|
|
|
576
612
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
577
613
|
*/
|
|
578
614
|
async pdfSeparate(file, outputPattern, options = {}) {
|
|
615
|
+
/** @type {PopplerAcceptedOptions} */
|
|
579
616
|
const acceptedOptions = {
|
|
580
617
|
firstPageToExtract: { arg: "-f", type: "number" },
|
|
581
618
|
lastPageToExtract: { arg: "-l", type: "number" },
|
|
@@ -584,7 +621,7 @@ class Poppler {
|
|
|
584
621
|
|
|
585
622
|
try {
|
|
586
623
|
const { stderr } = await execFileAsync(
|
|
587
|
-
pathResolve(this
|
|
624
|
+
pathResolve(this.#popplerPath, "pdfseparate"),
|
|
588
625
|
["-v"]
|
|
589
626
|
);
|
|
590
627
|
|
|
@@ -595,7 +632,7 @@ class Poppler {
|
|
|
595
632
|
args.push(file, outputPattern);
|
|
596
633
|
|
|
597
634
|
const { stdout } = await execFileAsync(
|
|
598
|
-
pathResolve(this
|
|
635
|
+
pathResolve(this.#popplerPath, "pdfseparate"),
|
|
599
636
|
args
|
|
600
637
|
);
|
|
601
638
|
return Promise.resolve(stdout);
|
|
@@ -712,6 +749,7 @@ class Poppler {
|
|
|
712
749
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
713
750
|
*/
|
|
714
751
|
async pdfToCairo(file, outputFile, options = {}) {
|
|
752
|
+
/** @type {PopplerAcceptedOptions} */
|
|
715
753
|
const acceptedOptions = {
|
|
716
754
|
antialias: { arg: "-antialias", type: "string" },
|
|
717
755
|
cropBox: { arg: "-cropbox", type: "boolean" },
|
|
@@ -768,7 +806,7 @@ class Poppler {
|
|
|
768
806
|
|
|
769
807
|
try {
|
|
770
808
|
const { stderr } = await execFileAsync(
|
|
771
|
-
pathResolve(this
|
|
809
|
+
pathResolve(this.#popplerPath, "pdftocairo"),
|
|
772
810
|
["-v"]
|
|
773
811
|
);
|
|
774
812
|
|
|
@@ -784,7 +822,7 @@ class Poppler {
|
|
|
784
822
|
);
|
|
785
823
|
|
|
786
824
|
const child = spawn(
|
|
787
|
-
pathResolve(this
|
|
825
|
+
pathResolve(this.#popplerPath, "pdftocairo"),
|
|
788
826
|
args
|
|
789
827
|
);
|
|
790
828
|
|
|
@@ -822,6 +860,7 @@ class Poppler {
|
|
|
822
860
|
} else {
|
|
823
861
|
reject(
|
|
824
862
|
new Error(
|
|
863
|
+
// @ts-ignore: Second operand used if code is not in errorMessages
|
|
825
864
|
errorMessages[code] ||
|
|
826
865
|
`pdftocairo ${args.join(
|
|
827
866
|
" "
|
|
@@ -839,7 +878,7 @@ class Poppler {
|
|
|
839
878
|
/**
|
|
840
879
|
* @author Frazer Smith
|
|
841
880
|
* @description Converts a PDF file to HTML.
|
|
842
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
881
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
843
882
|
* @param {string} [outputFile] - Filepath of the file to output the results to.
|
|
844
883
|
* If `undefined` then Poppler will use the directory and name of the original file
|
|
845
884
|
* and create a new file, with `-html` appended to the end of the filename.
|
|
@@ -877,6 +916,7 @@ class Poppler {
|
|
|
877
916
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
878
917
|
*/
|
|
879
918
|
async pdfToHtml(file, outputFile, options = {}) {
|
|
919
|
+
/** @type {PopplerAcceptedOptions} */
|
|
880
920
|
const acceptedOptions = {
|
|
881
921
|
complexOutput: { arg: "-c", type: "boolean" },
|
|
882
922
|
dataUrls: {
|
|
@@ -909,7 +949,7 @@ class Poppler {
|
|
|
909
949
|
|
|
910
950
|
try {
|
|
911
951
|
const { stderr } = await execFileAsync(
|
|
912
|
-
pathResolve(this
|
|
952
|
+
pathResolve(this.#popplerPath, "pdftohtml"),
|
|
913
953
|
["-v"]
|
|
914
954
|
);
|
|
915
955
|
|
|
@@ -926,7 +966,7 @@ class Poppler {
|
|
|
926
966
|
}
|
|
927
967
|
|
|
928
968
|
const child = spawn(
|
|
929
|
-
pathResolve(this
|
|
969
|
+
pathResolve(this.#popplerPath, "pdftohtml"),
|
|
930
970
|
args
|
|
931
971
|
);
|
|
932
972
|
|
|
@@ -968,7 +1008,7 @@ class Poppler {
|
|
|
968
1008
|
* @description Converts a PDF file to colour image files in Portable Pixmap (PPM) format,
|
|
969
1009
|
* grayscale image files in Portable Graymap (PGM) format, or monochrome image files
|
|
970
1010
|
* in Portable Bitmap (PBM) format.
|
|
971
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
1011
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
972
1012
|
* @param {string} outputPath - Filepath to output the results to.
|
|
973
1013
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
974
1014
|
* @param {('no'|'yes')} [options.antialiasFonts] - Enable or disable font anti-aliasing.
|
|
@@ -1038,6 +1078,7 @@ class Poppler {
|
|
|
1038
1078
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
1039
1079
|
*/
|
|
1040
1080
|
async pdfToPpm(file, outputPath, options = {}) {
|
|
1081
|
+
/** @type {PopplerAcceptedOptions} */
|
|
1041
1082
|
const acceptedOptions = {
|
|
1042
1083
|
antialiasFonts: { arg: "-aa", type: "string" },
|
|
1043
1084
|
antialiasVectors: { arg: "-aaVector", type: "string" },
|
|
@@ -1110,7 +1151,7 @@ class Poppler {
|
|
|
1110
1151
|
|
|
1111
1152
|
try {
|
|
1112
1153
|
const { stderr } = await execFileAsync(
|
|
1113
|
-
pathResolve(this
|
|
1154
|
+
pathResolve(this.#popplerPath, "pdftoppm"),
|
|
1114
1155
|
["-v"]
|
|
1115
1156
|
);
|
|
1116
1157
|
|
|
@@ -1123,7 +1164,7 @@ class Poppler {
|
|
|
1123
1164
|
args.push(Buffer.isBuffer(file) ? "-" : file, outputPath);
|
|
1124
1165
|
|
|
1125
1166
|
const child = spawn(
|
|
1126
|
-
pathResolve(this
|
|
1167
|
+
pathResolve(this.#popplerPath, "pdftoppm"),
|
|
1127
1168
|
args
|
|
1128
1169
|
);
|
|
1129
1170
|
|
|
@@ -1147,6 +1188,7 @@ class Poppler {
|
|
|
1147
1188
|
} else {
|
|
1148
1189
|
reject(
|
|
1149
1190
|
new Error(
|
|
1191
|
+
// @ts-ignore: Second operand used if code is not in errorMessages
|
|
1150
1192
|
errorMessages[code] ||
|
|
1151
1193
|
`pdftoppm ${args.join(
|
|
1152
1194
|
" "
|
|
@@ -1164,7 +1206,7 @@ class Poppler {
|
|
|
1164
1206
|
/**
|
|
1165
1207
|
* @author Frazer Smith
|
|
1166
1208
|
* @description Converts a PDF file to PostScript (PS).
|
|
1167
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
1209
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
1168
1210
|
* @param {string} [outputFile] - Filepath of the file to output the results to.
|
|
1169
1211
|
* If `undefined` then will write output to stdout.
|
|
1170
1212
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
@@ -1271,6 +1313,7 @@ class Poppler {
|
|
|
1271
1313
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
1272
1314
|
*/
|
|
1273
1315
|
async pdfToPs(file, outputFile, options = {}) {
|
|
1316
|
+
/** @type {PopplerAcceptedOptions} */
|
|
1274
1317
|
const acceptedOptions = {
|
|
1275
1318
|
antialias: { arg: "-aaRaster", type: "string" },
|
|
1276
1319
|
binary: { arg: "-binary", type: "boolean" },
|
|
@@ -1342,7 +1385,7 @@ class Poppler {
|
|
|
1342
1385
|
|
|
1343
1386
|
try {
|
|
1344
1387
|
const { stderr } = await execFileAsync(
|
|
1345
|
-
pathResolve(this
|
|
1388
|
+
pathResolve(this.#popplerPath, "pdftops"),
|
|
1346
1389
|
["-v"]
|
|
1347
1390
|
);
|
|
1348
1391
|
|
|
@@ -1358,7 +1401,7 @@ class Poppler {
|
|
|
1358
1401
|
);
|
|
1359
1402
|
|
|
1360
1403
|
const child = spawn(
|
|
1361
|
-
pathResolve(this
|
|
1404
|
+
pathResolve(this.#popplerPath, "pdftops"),
|
|
1362
1405
|
args
|
|
1363
1406
|
);
|
|
1364
1407
|
|
|
@@ -1389,6 +1432,7 @@ class Poppler {
|
|
|
1389
1432
|
} else {
|
|
1390
1433
|
reject(
|
|
1391
1434
|
new Error(
|
|
1435
|
+
// @ts-ignore: Second operand used if code is not in errorMessages
|
|
1392
1436
|
errorMessages[code] ||
|
|
1393
1437
|
`pdftops ${args.join(
|
|
1394
1438
|
" "
|
|
@@ -1406,7 +1450,7 @@ class Poppler {
|
|
|
1406
1450
|
/**
|
|
1407
1451
|
* @author Frazer Smith
|
|
1408
1452
|
* @description Converts a PDF file to TXT.
|
|
1409
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
1453
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
1410
1454
|
* @param {string} [outputFile] - Filepath of the file to output the results to.
|
|
1411
1455
|
* If `undefined` then will write output to stdout.
|
|
1412
1456
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
@@ -1452,6 +1496,7 @@ class Poppler {
|
|
|
1452
1496
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
1453
1497
|
*/
|
|
1454
1498
|
async pdfToText(file, outputFile, options = {}) {
|
|
1499
|
+
/** @type {PopplerAcceptedOptions} */
|
|
1455
1500
|
const acceptedOptions = {
|
|
1456
1501
|
boundingBoxXhtml: { arg: "-bbox", type: "boolean" },
|
|
1457
1502
|
boundingBoxXhtmlLayout: {
|
|
@@ -1492,7 +1537,7 @@ class Poppler {
|
|
|
1492
1537
|
|
|
1493
1538
|
try {
|
|
1494
1539
|
const { stderr } = await execFileAsync(
|
|
1495
|
-
pathResolve(this
|
|
1540
|
+
pathResolve(this.#popplerPath, "pdftotext"),
|
|
1496
1541
|
["-v"]
|
|
1497
1542
|
);
|
|
1498
1543
|
|
|
@@ -1508,7 +1553,7 @@ class Poppler {
|
|
|
1508
1553
|
);
|
|
1509
1554
|
|
|
1510
1555
|
const child = spawn(
|
|
1511
|
-
pathResolve(this
|
|
1556
|
+
pathResolve(this.#popplerPath, "pdftotext"),
|
|
1512
1557
|
args
|
|
1513
1558
|
);
|
|
1514
1559
|
|
|
@@ -1541,6 +1586,7 @@ class Poppler {
|
|
|
1541
1586
|
} else {
|
|
1542
1587
|
reject(
|
|
1543
1588
|
new Error(
|
|
1589
|
+
// @ts-ignore: Second operand used if code is not in errorMessages
|
|
1544
1590
|
errorMessages[code] ||
|
|
1545
1591
|
`pdftotext ${args.join(
|
|
1546
1592
|
" "
|
|
@@ -1567,13 +1613,14 @@ class Poppler {
|
|
|
1567
1613
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
1568
1614
|
*/
|
|
1569
1615
|
async pdfUnite(files, outputFile, options = {}) {
|
|
1616
|
+
/** @type {PopplerAcceptedOptions} */
|
|
1570
1617
|
const acceptedOptions = {
|
|
1571
1618
|
printVersionInfo: { arg: "-v", type: "boolean" },
|
|
1572
1619
|
};
|
|
1573
1620
|
|
|
1574
1621
|
try {
|
|
1575
1622
|
const { stderr } = await execFileAsync(
|
|
1576
|
-
pathResolve(this
|
|
1623
|
+
pathResolve(this.#popplerPath, "pdfunite"),
|
|
1577
1624
|
["-v"]
|
|
1578
1625
|
);
|
|
1579
1626
|
|
|
@@ -1581,13 +1628,10 @@ class Poppler {
|
|
|
1581
1628
|
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
1582
1629
|
|
|
1583
1630
|
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
1584
|
-
|
|
1585
|
-
args.push(element);
|
|
1586
|
-
});
|
|
1587
|
-
args.push(outputFile);
|
|
1631
|
+
args.push(...files, outputFile);
|
|
1588
1632
|
|
|
1589
1633
|
const { stdout } = await execFileAsync(
|
|
1590
|
-
pathResolve(this
|
|
1634
|
+
pathResolve(this.#popplerPath, "pdfunite"),
|
|
1591
1635
|
args
|
|
1592
1636
|
);
|
|
1593
1637
|
return Promise.resolve(stdout);
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
export default Poppler;
|
|
2
|
+
export type OptionDetails = {
|
|
3
|
+
/**
|
|
4
|
+
* The argument to pass to the binary.
|
|
5
|
+
*/
|
|
6
|
+
arg: string;
|
|
7
|
+
/**
|
|
8
|
+
* The type of the option.
|
|
9
|
+
*/
|
|
10
|
+
type: ("boolean" | "number" | "string");
|
|
11
|
+
/**
|
|
12
|
+
* The minimum version of the binary that supports this option.
|
|
13
|
+
*/
|
|
14
|
+
minVersion?: string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The maximum version of the binary that supports this option (optional).
|
|
17
|
+
*/
|
|
18
|
+
maxVersion?: string | undefined;
|
|
19
|
+
};
|
|
20
|
+
export type PopplerAcceptedOptions = Record<string, OptionDetails>;
|
|
2
21
|
export class Poppler {
|
|
3
22
|
/**
|
|
4
23
|
* @param {string} [binPath] - Path of poppler-utils binaries.
|
|
@@ -8,7 +27,11 @@ export class Poppler {
|
|
|
8
27
|
* if a local installation is not found.
|
|
9
28
|
*/
|
|
10
29
|
constructor(binPath?: string);
|
|
11
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @description Returns the path of the Poppler binaries.
|
|
32
|
+
* @returns {string} Path of Poppler binaries.
|
|
33
|
+
*/
|
|
34
|
+
get path(): string;
|
|
12
35
|
/**
|
|
13
36
|
* @author Frazer Smith
|
|
14
37
|
* @description Embeds files (attachments) into a PDF file.
|
|
@@ -21,8 +44,8 @@ export class Poppler {
|
|
|
21
44
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
22
45
|
*/
|
|
23
46
|
pdfAttach(file: string, fileToAttach: string, outputFile: string, options?: {
|
|
24
|
-
printVersionInfo?: boolean;
|
|
25
|
-
replace?: boolean;
|
|
47
|
+
printVersionInfo?: boolean | undefined;
|
|
48
|
+
replace?: boolean | undefined;
|
|
26
49
|
}): Promise<string>;
|
|
27
50
|
/**
|
|
28
51
|
* @author Frazer Smith
|
|
@@ -51,20 +74,20 @@ export class Poppler {
|
|
|
51
74
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
52
75
|
*/
|
|
53
76
|
pdfDetach(file: string, options?: {
|
|
54
|
-
listEmbedded?: boolean;
|
|
55
|
-
outputEncoding?: string;
|
|
56
|
-
ownerPassword?: string;
|
|
57
|
-
outputPath?: string;
|
|
58
|
-
printVersionInfo?: boolean;
|
|
59
|
-
saveAllFiles?: boolean;
|
|
60
|
-
saveFile?: string;
|
|
61
|
-
saveSpecificFile?: number;
|
|
62
|
-
userPassword?: string;
|
|
77
|
+
listEmbedded?: boolean | undefined;
|
|
78
|
+
outputEncoding?: string | undefined;
|
|
79
|
+
ownerPassword?: string | undefined;
|
|
80
|
+
outputPath?: string | undefined;
|
|
81
|
+
printVersionInfo?: boolean | undefined;
|
|
82
|
+
saveAllFiles?: boolean | undefined;
|
|
83
|
+
saveFile?: string | undefined;
|
|
84
|
+
saveSpecificFile?: number | undefined;
|
|
85
|
+
userPassword?: string | undefined;
|
|
63
86
|
}): Promise<string>;
|
|
64
87
|
/**
|
|
65
88
|
* @author Frazer Smith
|
|
66
89
|
* @description Lists the fonts used in a PDF file along with various information for each font.
|
|
67
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
90
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
68
91
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
69
92
|
* @param {number} [options.firstPageToExamine] - Specifies the first page to examine.
|
|
70
93
|
* @param {number} [options.lastPageToExamine] - Specifies the last page to examine.
|
|
@@ -75,18 +98,18 @@ export class Poppler {
|
|
|
75
98
|
* @param {string} [options.userPassword] - User password (for encrypted files).
|
|
76
99
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
77
100
|
*/
|
|
78
|
-
pdfFonts(file: Buffer | string, options?: {
|
|
79
|
-
firstPageToExamine?: number;
|
|
80
|
-
lastPageToExamine?: number;
|
|
81
|
-
listSubstitutes?: boolean;
|
|
82
|
-
ownerPassword?: string;
|
|
83
|
-
printVersionInfo?: boolean;
|
|
84
|
-
userPassword?: string;
|
|
101
|
+
pdfFonts(file: (Buffer | string), options?: {
|
|
102
|
+
firstPageToExamine?: number | undefined;
|
|
103
|
+
lastPageToExamine?: number | undefined;
|
|
104
|
+
listSubstitutes?: boolean | undefined;
|
|
105
|
+
ownerPassword?: string | undefined;
|
|
106
|
+
printVersionInfo?: boolean | undefined;
|
|
107
|
+
userPassword?: string | undefined;
|
|
85
108
|
}): Promise<string>;
|
|
86
109
|
/**
|
|
87
110
|
* @author Frazer Smith
|
|
88
111
|
* @description Saves images from a PDF file as PPM, PBM, PNG, TIFF, JPEG, JPEG2000, or JBIG2 files.
|
|
89
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
112
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
90
113
|
* @param {string} [outputPrefix] - Filename prefix of output files.
|
|
91
114
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
92
115
|
* @param {boolean} [options.allFiles] - Write JPEG, JPEG2000, JBIG2, and CCITT images in their native format.
|
|
@@ -107,25 +130,25 @@ export class Poppler {
|
|
|
107
130
|
* @param {string} [options.userPassword] - Specify the user password for the PDF file.
|
|
108
131
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
109
132
|
*/
|
|
110
|
-
pdfImages(file: Buffer | string, outputPrefix?: string, options?: {
|
|
111
|
-
allFiles?: boolean;
|
|
112
|
-
ccittFile?: boolean;
|
|
113
|
-
firstPageToConvert?: number;
|
|
114
|
-
lastPageToConvert?: number;
|
|
115
|
-
jbig2File?: boolean;
|
|
116
|
-
jpeg2000File?: boolean;
|
|
117
|
-
jpegFile?: boolean;
|
|
118
|
-
list?: boolean;
|
|
119
|
-
ownerPassword?: string;
|
|
120
|
-
pngFile?: boolean;
|
|
121
|
-
printVersionInfo?: boolean;
|
|
122
|
-
tiffFile?: boolean;
|
|
123
|
-
userPassword?: string;
|
|
133
|
+
pdfImages(file: (Buffer | string), outputPrefix?: string, options?: {
|
|
134
|
+
allFiles?: boolean | undefined;
|
|
135
|
+
ccittFile?: boolean | undefined;
|
|
136
|
+
firstPageToConvert?: number | undefined;
|
|
137
|
+
lastPageToConvert?: number | undefined;
|
|
138
|
+
jbig2File?: boolean | undefined;
|
|
139
|
+
jpeg2000File?: boolean | undefined;
|
|
140
|
+
jpegFile?: boolean | undefined;
|
|
141
|
+
list?: boolean | undefined;
|
|
142
|
+
ownerPassword?: string | undefined;
|
|
143
|
+
pngFile?: boolean | undefined;
|
|
144
|
+
printVersionInfo?: boolean | undefined;
|
|
145
|
+
tiffFile?: boolean | undefined;
|
|
146
|
+
userPassword?: string | undefined;
|
|
124
147
|
}): Promise<string>;
|
|
125
148
|
/**
|
|
126
149
|
* @author Frazer Smith
|
|
127
150
|
* @description Prints the contents of the `Info` dictionary from a PDF file.
|
|
128
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
151
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
129
152
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
130
153
|
* @param {number} [options.firstPageToConvert] - First page to print.
|
|
131
154
|
* @param {number} [options.lastPageToConvert] - Last page to print.
|
|
@@ -156,24 +179,24 @@ export class Poppler {
|
|
|
156
179
|
* @returns {Promise<object|string>} A promise that resolves with a stdout string or JSON object if
|
|
157
180
|
* `options.printAsJson` is `true`, or rejects with an `Error` object.
|
|
158
181
|
*/
|
|
159
|
-
pdfInfo(file: Buffer | string, options?: {
|
|
160
|
-
firstPageToConvert?: number;
|
|
161
|
-
lastPageToConvert?: number;
|
|
162
|
-
listEncodingOptions?: boolean;
|
|
163
|
-
outputEncoding?: string;
|
|
164
|
-
ownerPassword?: string;
|
|
165
|
-
printAsJson?: boolean;
|
|
166
|
-
printBoundingBoxes?: boolean;
|
|
167
|
-
printDocStruct?: boolean;
|
|
168
|
-
printDocStructText?: boolean;
|
|
169
|
-
printIsoDates?: boolean;
|
|
170
|
-
printJS?: boolean;
|
|
171
|
-
printMetadata?: boolean;
|
|
172
|
-
printNamedDests?: boolean;
|
|
173
|
-
printRawDates?: boolean;
|
|
174
|
-
printUrls?: boolean;
|
|
175
|
-
printVersionInfo?: boolean;
|
|
176
|
-
userPassword?: string;
|
|
182
|
+
pdfInfo(file: (Buffer | string), options?: {
|
|
183
|
+
firstPageToConvert?: number | undefined;
|
|
184
|
+
lastPageToConvert?: number | undefined;
|
|
185
|
+
listEncodingOptions?: boolean | undefined;
|
|
186
|
+
outputEncoding?: string | undefined;
|
|
187
|
+
ownerPassword?: string | undefined;
|
|
188
|
+
printAsJson?: boolean | undefined;
|
|
189
|
+
printBoundingBoxes?: boolean | undefined;
|
|
190
|
+
printDocStruct?: boolean | undefined;
|
|
191
|
+
printDocStructText?: boolean | undefined;
|
|
192
|
+
printIsoDates?: boolean | undefined;
|
|
193
|
+
printJS?: boolean | undefined;
|
|
194
|
+
printMetadata?: boolean | undefined;
|
|
195
|
+
printNamedDests?: boolean | undefined;
|
|
196
|
+
printRawDates?: boolean | undefined;
|
|
197
|
+
printUrls?: boolean | undefined;
|
|
198
|
+
printVersionInfo?: boolean | undefined;
|
|
199
|
+
userPassword?: string | undefined;
|
|
177
200
|
}): Promise<object | string>;
|
|
178
201
|
/**
|
|
179
202
|
* @author Frazer Smith
|
|
@@ -193,9 +216,9 @@ export class Poppler {
|
|
|
193
216
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
194
217
|
*/
|
|
195
218
|
pdfSeparate(file: string, outputPattern: string, options?: {
|
|
196
|
-
firstPageToExtract?: number;
|
|
197
|
-
lastPageToExtract?: number;
|
|
198
|
-
printVersionInfo?: boolean;
|
|
219
|
+
firstPageToExtract?: number | undefined;
|
|
220
|
+
lastPageToExtract?: number | undefined;
|
|
221
|
+
printVersionInfo?: boolean | undefined;
|
|
199
222
|
}): Promise<string>;
|
|
200
223
|
/**
|
|
201
224
|
* @author Frazer Smith
|
|
@@ -305,58 +328,58 @@ export class Poppler {
|
|
|
305
328
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
306
329
|
*/
|
|
307
330
|
pdfToCairo(file: Buffer | string, outputFile?: string, options?: {
|
|
308
|
-
antialias?:
|
|
309
|
-
cropBox?: boolean;
|
|
310
|
-
cropHeight?: number;
|
|
311
|
-
cropSize?: number;
|
|
312
|
-
cropWidth?: number;
|
|
313
|
-
cropXAxis?: number;
|
|
314
|
-
cropYAxis?: number;
|
|
315
|
-
duplex?: boolean;
|
|
316
|
-
epsFile?: boolean;
|
|
317
|
-
evenPagesOnly?: boolean;
|
|
318
|
-
fillPage?: boolean;
|
|
319
|
-
firstPageToConvert?: number;
|
|
320
|
-
grayscaleFile?: boolean;
|
|
321
|
-
iccFile?: string;
|
|
322
|
-
jpegFile?: boolean;
|
|
323
|
-
jpegOptions?: string;
|
|
324
|
-
lastPageToConvert?: number;
|
|
325
|
-
monochromeFile?: boolean;
|
|
326
|
-
noCenter?: boolean;
|
|
327
|
-
noCrop?: boolean;
|
|
328
|
-
noShrink?: boolean;
|
|
329
|
-
oddPagesOnly?: boolean;
|
|
330
|
-
originalPageSizes?: boolean;
|
|
331
|
-
ownerPassword?: string;
|
|
332
|
-
paperHeight?: number;
|
|
333
|
-
paperSize?:
|
|
334
|
-
paperWidth?: number;
|
|
335
|
-
pdfFile?: boolean;
|
|
336
|
-
pngFile?: boolean;
|
|
337
|
-
printVersionInfo?: boolean;
|
|
338
|
-
printDocStruct?: boolean;
|
|
339
|
-
psFile?: boolean;
|
|
340
|
-
psLevel2?: boolean;
|
|
341
|
-
psLevel3?: boolean;
|
|
342
|
-
quiet?: boolean;
|
|
343
|
-
resolutionXAxis?: number;
|
|
344
|
-
resolutionXYAxis?: number;
|
|
345
|
-
resolutionYAxis?: number;
|
|
346
|
-
scalePageTo?: number;
|
|
347
|
-
scalePageToXAxis?: number;
|
|
348
|
-
scalePageToYAxis?: number;
|
|
349
|
-
singleFile?: boolean;
|
|
350
|
-
svgFile?: boolean;
|
|
351
|
-
tiffCompression?:
|
|
352
|
-
tiffFile?: boolean;
|
|
353
|
-
transparentPageColor?: boolean;
|
|
354
|
-
userPassword?: string;
|
|
331
|
+
antialias?: "none" | "default" | "best" | "fast" | "good" | "gray" | "subpixel" | undefined;
|
|
332
|
+
cropBox?: boolean | undefined;
|
|
333
|
+
cropHeight?: number | undefined;
|
|
334
|
+
cropSize?: number | undefined;
|
|
335
|
+
cropWidth?: number | undefined;
|
|
336
|
+
cropXAxis?: number | undefined;
|
|
337
|
+
cropYAxis?: number | undefined;
|
|
338
|
+
duplex?: boolean | undefined;
|
|
339
|
+
epsFile?: boolean | undefined;
|
|
340
|
+
evenPagesOnly?: boolean | undefined;
|
|
341
|
+
fillPage?: boolean | undefined;
|
|
342
|
+
firstPageToConvert?: number | undefined;
|
|
343
|
+
grayscaleFile?: boolean | undefined;
|
|
344
|
+
iccFile?: string | undefined;
|
|
345
|
+
jpegFile?: boolean | undefined;
|
|
346
|
+
jpegOptions?: string | undefined;
|
|
347
|
+
lastPageToConvert?: number | undefined;
|
|
348
|
+
monochromeFile?: boolean | undefined;
|
|
349
|
+
noCenter?: boolean | undefined;
|
|
350
|
+
noCrop?: boolean | undefined;
|
|
351
|
+
noShrink?: boolean | undefined;
|
|
352
|
+
oddPagesOnly?: boolean | undefined;
|
|
353
|
+
originalPageSizes?: boolean | undefined;
|
|
354
|
+
ownerPassword?: string | undefined;
|
|
355
|
+
paperHeight?: number | undefined;
|
|
356
|
+
paperSize?: "match" | "A3" | "A4" | "legal" | "letter" | undefined;
|
|
357
|
+
paperWidth?: number | undefined;
|
|
358
|
+
pdfFile?: boolean | undefined;
|
|
359
|
+
pngFile?: boolean | undefined;
|
|
360
|
+
printVersionInfo?: boolean | undefined;
|
|
361
|
+
printDocStruct?: boolean | undefined;
|
|
362
|
+
psFile?: boolean | undefined;
|
|
363
|
+
psLevel2?: boolean | undefined;
|
|
364
|
+
psLevel3?: boolean | undefined;
|
|
365
|
+
quiet?: boolean | undefined;
|
|
366
|
+
resolutionXAxis?: number | undefined;
|
|
367
|
+
resolutionXYAxis?: number | undefined;
|
|
368
|
+
resolutionYAxis?: number | undefined;
|
|
369
|
+
scalePageTo?: number | undefined;
|
|
370
|
+
scalePageToXAxis?: number | undefined;
|
|
371
|
+
scalePageToYAxis?: number | undefined;
|
|
372
|
+
singleFile?: boolean | undefined;
|
|
373
|
+
svgFile?: boolean | undefined;
|
|
374
|
+
tiffCompression?: "none" | "deflate" | "jpeg" | "lzw" | "packbits" | undefined;
|
|
375
|
+
tiffFile?: boolean | undefined;
|
|
376
|
+
transparentPageColor?: boolean | undefined;
|
|
377
|
+
userPassword?: string | undefined;
|
|
355
378
|
}): Promise<string>;
|
|
356
379
|
/**
|
|
357
380
|
* @author Frazer Smith
|
|
358
381
|
* @description Converts a PDF file to HTML.
|
|
359
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
382
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
360
383
|
* @param {string} [outputFile] - Filepath of the file to output the results to.
|
|
361
384
|
* If `undefined` then Poppler will use the directory and name of the original file
|
|
362
385
|
* and create a new file, with `-html` appended to the end of the filename.
|
|
@@ -393,37 +416,37 @@ export class Poppler {
|
|
|
393
416
|
* @param {number} [options.zoom] - Zoom the PDF document (default 1.5).
|
|
394
417
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
395
418
|
*/
|
|
396
|
-
pdfToHtml(file: Buffer | string, outputFile?: string, options?: {
|
|
397
|
-
complexOutput?: boolean;
|
|
398
|
-
dataUrls?: boolean;
|
|
399
|
-
exchangePdfLinks?: boolean;
|
|
400
|
-
extractHidden?: boolean;
|
|
401
|
-
firstPageToConvert?: number;
|
|
402
|
-
fontFullName?: boolean;
|
|
403
|
-
ignoreImages?: boolean;
|
|
404
|
-
imageFormat?:
|
|
405
|
-
lastPageToConvert?: number;
|
|
406
|
-
noDrm?: boolean;
|
|
407
|
-
noFrames?: boolean;
|
|
408
|
-
noMergeParagraph?: boolean;
|
|
409
|
-
noRoundedCoordinates?: boolean;
|
|
410
|
-
outputEncoding?: string;
|
|
411
|
-
ownerPassword?: string;
|
|
412
|
-
printVersionInfo?: boolean;
|
|
413
|
-
quiet?: boolean;
|
|
414
|
-
singlePage?: boolean;
|
|
415
|
-
stdout?: boolean;
|
|
416
|
-
userPassword?: string;
|
|
417
|
-
wordBreakThreshold?: number;
|
|
418
|
-
xmlOutput?: boolean;
|
|
419
|
-
zoom?: number;
|
|
419
|
+
pdfToHtml(file: (Buffer | string), outputFile?: string, options?: {
|
|
420
|
+
complexOutput?: boolean | undefined;
|
|
421
|
+
dataUrls?: boolean | undefined;
|
|
422
|
+
exchangePdfLinks?: boolean | undefined;
|
|
423
|
+
extractHidden?: boolean | undefined;
|
|
424
|
+
firstPageToConvert?: number | undefined;
|
|
425
|
+
fontFullName?: boolean | undefined;
|
|
426
|
+
ignoreImages?: boolean | undefined;
|
|
427
|
+
imageFormat?: "JPG" | "PNG" | undefined;
|
|
428
|
+
lastPageToConvert?: number | undefined;
|
|
429
|
+
noDrm?: boolean | undefined;
|
|
430
|
+
noFrames?: boolean | undefined;
|
|
431
|
+
noMergeParagraph?: boolean | undefined;
|
|
432
|
+
noRoundedCoordinates?: boolean | undefined;
|
|
433
|
+
outputEncoding?: string | undefined;
|
|
434
|
+
ownerPassword?: string | undefined;
|
|
435
|
+
printVersionInfo?: boolean | undefined;
|
|
436
|
+
quiet?: boolean | undefined;
|
|
437
|
+
singlePage?: boolean | undefined;
|
|
438
|
+
stdout?: boolean | undefined;
|
|
439
|
+
userPassword?: string | undefined;
|
|
440
|
+
wordBreakThreshold?: number | undefined;
|
|
441
|
+
xmlOutput?: boolean | undefined;
|
|
442
|
+
zoom?: number | undefined;
|
|
420
443
|
}): Promise<string>;
|
|
421
444
|
/**
|
|
422
445
|
* @author Frazer Smith
|
|
423
446
|
* @description Converts a PDF file to colour image files in Portable Pixmap (PPM) format,
|
|
424
447
|
* grayscale image files in Portable Graymap (PGM) format, or monochrome image files
|
|
425
448
|
* in Portable Bitmap (PBM) format.
|
|
426
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
449
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
427
450
|
* @param {string} outputPath - Filepath to output the results to.
|
|
428
451
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
429
452
|
* @param {('no'|'yes')} [options.antialiasFonts] - Enable or disable font anti-aliasing.
|
|
@@ -492,51 +515,51 @@ export class Poppler {
|
|
|
492
515
|
* @param {string} [options.userPassword] - Specify the user password for the PDF file.
|
|
493
516
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
494
517
|
*/
|
|
495
|
-
pdfToPpm(file: Buffer | string, outputPath: string, options?: {
|
|
496
|
-
antialiasFonts?:
|
|
497
|
-
antialiasVectors?:
|
|
498
|
-
cropBox?: boolean;
|
|
499
|
-
cropHeight?: number;
|
|
500
|
-
cropSize?: number;
|
|
501
|
-
cropWidth?: number;
|
|
502
|
-
cropXAxis?: number;
|
|
503
|
-
cropYAxis?: number;
|
|
504
|
-
defaultCmykProfile?: string;
|
|
505
|
-
defaultGrayProfile?: string;
|
|
506
|
-
defaultRgbProfile?: string;
|
|
507
|
-
displayProfile?: string;
|
|
508
|
-
evenPagesOnly?: boolean;
|
|
509
|
-
firstPageToConvert?: number;
|
|
510
|
-
freetype?:
|
|
511
|
-
forcePageNumber?: boolean;
|
|
512
|
-
grayscaleFile?: boolean;
|
|
513
|
-
hideAnnotations?: boolean;
|
|
514
|
-
jpegFile?: boolean;
|
|
515
|
-
lastPageToConvert?: number;
|
|
516
|
-
monochromeFile?: boolean;
|
|
517
|
-
oddPagesOnly?: boolean;
|
|
518
|
-
ownerPassword?: string;
|
|
519
|
-
pngFile?: boolean;
|
|
520
|
-
printProgress?: boolean;
|
|
521
|
-
printVersionInfo?: boolean;
|
|
522
|
-
quiet?: boolean;
|
|
523
|
-
resolutionXAxis?: number;
|
|
524
|
-
resolutionXYAxis?: number;
|
|
525
|
-
resolutionYAxis?: number;
|
|
526
|
-
scalePageTo?: number;
|
|
527
|
-
scalePageToXAxis?: number;
|
|
528
|
-
scalePageToYAxis?: number;
|
|
529
|
-
separator?: string;
|
|
530
|
-
singleFile?: boolean;
|
|
531
|
-
thinLineMode?:
|
|
532
|
-
tiffCompression?:
|
|
533
|
-
tiffFile?: boolean;
|
|
534
|
-
userPassword?: string;
|
|
518
|
+
pdfToPpm(file: (Buffer | string), outputPath: string, options?: {
|
|
519
|
+
antialiasFonts?: "no" | "yes" | undefined;
|
|
520
|
+
antialiasVectors?: "no" | "yes" | undefined;
|
|
521
|
+
cropBox?: boolean | undefined;
|
|
522
|
+
cropHeight?: number | undefined;
|
|
523
|
+
cropSize?: number | undefined;
|
|
524
|
+
cropWidth?: number | undefined;
|
|
525
|
+
cropXAxis?: number | undefined;
|
|
526
|
+
cropYAxis?: number | undefined;
|
|
527
|
+
defaultCmykProfile?: string | undefined;
|
|
528
|
+
defaultGrayProfile?: string | undefined;
|
|
529
|
+
defaultRgbProfile?: string | undefined;
|
|
530
|
+
displayProfile?: string | undefined;
|
|
531
|
+
evenPagesOnly?: boolean | undefined;
|
|
532
|
+
firstPageToConvert?: number | undefined;
|
|
533
|
+
freetype?: "no" | "yes" | undefined;
|
|
534
|
+
forcePageNumber?: boolean | undefined;
|
|
535
|
+
grayscaleFile?: boolean | undefined;
|
|
536
|
+
hideAnnotations?: boolean | undefined;
|
|
537
|
+
jpegFile?: boolean | undefined;
|
|
538
|
+
lastPageToConvert?: number | undefined;
|
|
539
|
+
monochromeFile?: boolean | undefined;
|
|
540
|
+
oddPagesOnly?: boolean | undefined;
|
|
541
|
+
ownerPassword?: string | undefined;
|
|
542
|
+
pngFile?: boolean | undefined;
|
|
543
|
+
printProgress?: boolean | undefined;
|
|
544
|
+
printVersionInfo?: boolean | undefined;
|
|
545
|
+
quiet?: boolean | undefined;
|
|
546
|
+
resolutionXAxis?: number | undefined;
|
|
547
|
+
resolutionXYAxis?: number | undefined;
|
|
548
|
+
resolutionYAxis?: number | undefined;
|
|
549
|
+
scalePageTo?: number | undefined;
|
|
550
|
+
scalePageToXAxis?: number | undefined;
|
|
551
|
+
scalePageToYAxis?: number | undefined;
|
|
552
|
+
separator?: string | undefined;
|
|
553
|
+
singleFile?: boolean | undefined;
|
|
554
|
+
thinLineMode?: "none" | "shape" | "solid" | undefined;
|
|
555
|
+
tiffCompression?: "none" | "deflate" | "jpeg" | "lzw" | "packbits" | undefined;
|
|
556
|
+
tiffFile?: boolean | undefined;
|
|
557
|
+
userPassword?: string | undefined;
|
|
535
558
|
}): Promise<string>;
|
|
536
559
|
/**
|
|
537
560
|
* @author Frazer Smith
|
|
538
561
|
* @description Converts a PDF file to PostScript (PS).
|
|
539
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
562
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
540
563
|
* @param {string} [outputFile] - Filepath of the file to output the results to.
|
|
541
564
|
* If `undefined` then will write output to stdout.
|
|
542
565
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
@@ -642,53 +665,53 @@ export class Poppler {
|
|
|
642
665
|
* @param {string} [options.userPassword] - User password (for encrypted files).
|
|
643
666
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
644
667
|
*/
|
|
645
|
-
pdfToPs(file: Buffer | string, outputFile?: string, options?: {
|
|
646
|
-
antialias?:
|
|
647
|
-
binary?: boolean;
|
|
648
|
-
defaultCmykProfile?: string;
|
|
649
|
-
defaultGrayProfile?: string;
|
|
650
|
-
defaultRgbProfile?: string;
|
|
651
|
-
duplex?: boolean;
|
|
652
|
-
epsFile?: boolean;
|
|
653
|
-
fillPage?: boolean;
|
|
654
|
-
firstPageToConvert?: number;
|
|
655
|
-
form?: number;
|
|
656
|
-
lastPageToConvert?: number;
|
|
657
|
-
level1?: boolean;
|
|
658
|
-
level1Sep?: boolean;
|
|
659
|
-
level2?: boolean;
|
|
660
|
-
level2Sep?: boolean;
|
|
661
|
-
level3?: boolean;
|
|
662
|
-
level3Sep?: boolean;
|
|
663
|
-
noCenter?: boolean;
|
|
664
|
-
noCrop?: boolean;
|
|
665
|
-
noEmbedCIDFonts?: boolean;
|
|
666
|
-
noEmbedCIDTrueTypeFonts?: boolean;
|
|
667
|
-
noEmbedTrueTypeFonts?: boolean;
|
|
668
|
-
noEmbedType1Fonts?: boolean;
|
|
669
|
-
noShrink?: boolean;
|
|
670
|
-
opi?: boolean;
|
|
671
|
-
optimizecolorspace?: boolean;
|
|
672
|
-
originalPageSizes?: boolean;
|
|
673
|
-
overprint?: boolean;
|
|
674
|
-
ownerPassword?: string;
|
|
675
|
-
paperHeight?: number;
|
|
676
|
-
paperSize?:
|
|
677
|
-
paperWidth?: number;
|
|
678
|
-
passfonts?: boolean;
|
|
679
|
-
preload?: boolean;
|
|
680
|
-
printVersionInfo?: boolean;
|
|
681
|
-
processColorFormat?:
|
|
682
|
-
processColorProfile?: string;
|
|
683
|
-
quiet?: boolean;
|
|
684
|
-
rasterize?:
|
|
685
|
-
resolutionXYAxis?: number;
|
|
686
|
-
userPassword?: string;
|
|
668
|
+
pdfToPs(file: (Buffer | string), outputFile?: string, options?: {
|
|
669
|
+
antialias?: "no" | "yes" | undefined;
|
|
670
|
+
binary?: boolean | undefined;
|
|
671
|
+
defaultCmykProfile?: string | undefined;
|
|
672
|
+
defaultGrayProfile?: string | undefined;
|
|
673
|
+
defaultRgbProfile?: string | undefined;
|
|
674
|
+
duplex?: boolean | undefined;
|
|
675
|
+
epsFile?: boolean | undefined;
|
|
676
|
+
fillPage?: boolean | undefined;
|
|
677
|
+
firstPageToConvert?: number | undefined;
|
|
678
|
+
form?: number | undefined;
|
|
679
|
+
lastPageToConvert?: number | undefined;
|
|
680
|
+
level1?: boolean | undefined;
|
|
681
|
+
level1Sep?: boolean | undefined;
|
|
682
|
+
level2?: boolean | undefined;
|
|
683
|
+
level2Sep?: boolean | undefined;
|
|
684
|
+
level3?: boolean | undefined;
|
|
685
|
+
level3Sep?: boolean | undefined;
|
|
686
|
+
noCenter?: boolean | undefined;
|
|
687
|
+
noCrop?: boolean | undefined;
|
|
688
|
+
noEmbedCIDFonts?: boolean | undefined;
|
|
689
|
+
noEmbedCIDTrueTypeFonts?: boolean | undefined;
|
|
690
|
+
noEmbedTrueTypeFonts?: boolean | undefined;
|
|
691
|
+
noEmbedType1Fonts?: boolean | undefined;
|
|
692
|
+
noShrink?: boolean | undefined;
|
|
693
|
+
opi?: boolean | undefined;
|
|
694
|
+
optimizecolorspace?: boolean | undefined;
|
|
695
|
+
originalPageSizes?: boolean | undefined;
|
|
696
|
+
overprint?: boolean | undefined;
|
|
697
|
+
ownerPassword?: string | undefined;
|
|
698
|
+
paperHeight?: number | undefined;
|
|
699
|
+
paperSize?: "match" | "A3" | "A4" | "legal" | "letter" | undefined;
|
|
700
|
+
paperWidth?: number | undefined;
|
|
701
|
+
passfonts?: boolean | undefined;
|
|
702
|
+
preload?: boolean | undefined;
|
|
703
|
+
printVersionInfo?: boolean | undefined;
|
|
704
|
+
processColorFormat?: "CMYK8" | "MONO8" | "RGB8" | undefined;
|
|
705
|
+
processColorProfile?: string | undefined;
|
|
706
|
+
quiet?: boolean | undefined;
|
|
707
|
+
rasterize?: "always" | "never" | "whenneeded" | undefined;
|
|
708
|
+
resolutionXYAxis?: number | undefined;
|
|
709
|
+
userPassword?: string | undefined;
|
|
687
710
|
}): Promise<string>;
|
|
688
711
|
/**
|
|
689
712
|
* @author Frazer Smith
|
|
690
713
|
* @description Converts a PDF file to TXT.
|
|
691
|
-
* @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
714
|
+
* @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
|
|
692
715
|
* @param {string} [outputFile] - Filepath of the file to output the results to.
|
|
693
716
|
* If `undefined` then will write output to stdout.
|
|
694
717
|
* @param {object} [options] - Object containing options to pass to binary.
|
|
@@ -733,30 +756,30 @@ export class Poppler {
|
|
|
733
756
|
* @param {string} [options.userPassword] - User password (for encrypted files).
|
|
734
757
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
735
758
|
*/
|
|
736
|
-
pdfToText(file: Buffer | string, outputFile?: string, options?: {
|
|
737
|
-
boundingBoxXhtml?: boolean;
|
|
738
|
-
boundingBoxXhtmlLayout?: boolean;
|
|
739
|
-
cropBox?: boolean;
|
|
740
|
-
cropHeight?: number;
|
|
741
|
-
cropWidth?: number;
|
|
742
|
-
cropXAxis?: number;
|
|
743
|
-
cropYAxis?: number;
|
|
744
|
-
eolConvention?:
|
|
745
|
-
firstPageToConvert?: number;
|
|
746
|
-
fixedWidthLayout?: number;
|
|
747
|
-
generateHtmlMetaFile?: boolean;
|
|
748
|
-
generateTsvFile?: boolean;
|
|
749
|
-
lastPageToConvert?: number;
|
|
750
|
-
listEncodingOptions?: boolean;
|
|
751
|
-
maintainLayout?: boolean;
|
|
752
|
-
noDiagonalText?: boolean;
|
|
753
|
-
noPageBreaks?: boolean;
|
|
754
|
-
outputEncoding?: string;
|
|
755
|
-
ownerPassword?: string;
|
|
756
|
-
printVersionInfo?: boolean;
|
|
757
|
-
quiet?: boolean;
|
|
758
|
-
rawLayout?: boolean;
|
|
759
|
-
userPassword?: string;
|
|
759
|
+
pdfToText(file: (Buffer | string), outputFile?: string, options?: {
|
|
760
|
+
boundingBoxXhtml?: boolean | undefined;
|
|
761
|
+
boundingBoxXhtmlLayout?: boolean | undefined;
|
|
762
|
+
cropBox?: boolean | undefined;
|
|
763
|
+
cropHeight?: number | undefined;
|
|
764
|
+
cropWidth?: number | undefined;
|
|
765
|
+
cropXAxis?: number | undefined;
|
|
766
|
+
cropYAxis?: number | undefined;
|
|
767
|
+
eolConvention?: "dos" | "mac" | "unix" | undefined;
|
|
768
|
+
firstPageToConvert?: number | undefined;
|
|
769
|
+
fixedWidthLayout?: number | undefined;
|
|
770
|
+
generateHtmlMetaFile?: boolean | undefined;
|
|
771
|
+
generateTsvFile?: boolean | undefined;
|
|
772
|
+
lastPageToConvert?: number | undefined;
|
|
773
|
+
listEncodingOptions?: boolean | undefined;
|
|
774
|
+
maintainLayout?: boolean | undefined;
|
|
775
|
+
noDiagonalText?: boolean | undefined;
|
|
776
|
+
noPageBreaks?: boolean | undefined;
|
|
777
|
+
outputEncoding?: string | undefined;
|
|
778
|
+
ownerPassword?: string | undefined;
|
|
779
|
+
printVersionInfo?: boolean | undefined;
|
|
780
|
+
quiet?: boolean | undefined;
|
|
781
|
+
rawLayout?: boolean | undefined;
|
|
782
|
+
userPassword?: string | undefined;
|
|
760
783
|
}): Promise<string>;
|
|
761
784
|
/**
|
|
762
785
|
* @author Frazer Smith
|
|
@@ -770,6 +793,7 @@ export class Poppler {
|
|
|
770
793
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
771
794
|
*/
|
|
772
795
|
pdfUnite(files: string[], outputFile: string, options?: {
|
|
773
|
-
printVersionInfo?: boolean;
|
|
796
|
+
printVersionInfo?: boolean | undefined;
|
|
774
797
|
}): Promise<string>;
|
|
798
|
+
#private;
|
|
775
799
|
}
|