node-poppler 7.2.3 → 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 CHANGED
@@ -6,13 +6,13 @@
6
6
  [![Coverage status](https://coveralls.io/repos/github/Fdawgs/node-poppler/badge.svg?branch=main)](https://coveralls.io/github/Fdawgs/node-poppler?branch=main)
7
7
  [![code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat)](https://github.com/prettier/prettier)
8
8
 
9
- > Asynchronous node.js wrapper for the Poppler PDF rendering library
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 node.js wrapper around said utility binaries for easier use.
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
 
@@ -25,7 +25,7 @@ npm i node-poppler
25
25
  ### Linux and macOS/Darwin support
26
26
 
27
27
  Windows binaries are provided with this repository.
28
- For Linux users, you will need to download the `poppler-data` and `poppler-utils` binaries separately.
28
+ For Linux and Mac users, the `poppler-data` and `poppler-utils` binaries binary will need to be installed separately.
29
29
 
30
30
  An example of downloading the binaries on a Debian system:
31
31
 
@@ -33,15 +33,17 @@ An example of downloading the binaries on a Debian system:
33
33
  sudo apt-get install poppler-data poppler-utils
34
34
  ```
35
35
 
36
- For macOS users, you can download the latest versions with [Homebrew](https://brew.sh/):
36
+ For macOS users, the binaries can be installed with [Homebrew](https://brew.sh/):
37
37
 
38
38
  ```
39
39
  brew install poppler
40
40
  ```
41
41
 
42
- ## Example usage
42
+ ## API
43
+
44
+ API documentation can be found [here](https://github.com/Fdawgs/node-poppler/blob/main/API.md).
43
45
 
44
- Please refer to the [JSDoc comments in the source code](./src/index.js) or the [generated type definitions](https://www.npmjs.com/package/node-poppler?activeTab=code) for information on the available options.
46
+ ## Example usage
45
47
 
46
48
  ### poppler.pdfToCairo
47
49
 
@@ -79,7 +81,7 @@ const options = {
79
81
 
80
82
  const res = await poppler.pdfToCairo(file, undefined, options);
81
83
  // pdfToCairo writes to stdout using binary encoding if pdfFile or singleFile options are used
82
- await writeFile("new_file.pdf", res, { encoding: "binary" });
84
+ await writeFile("new_file.pdf", res, { encoding: "binary", flush: true });
83
85
  ```
84
86
 
85
87
  ### poppler.pdfToHtml
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-poppler",
3
- "version": "7.2.3",
4
- "description": "Asynchronous node.js wrapper for the Poppler PDF rendering library",
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,11 +47,10 @@
47
47
  "author": "Frazer Smith <frazer.dev@icloud.com>",
48
48
  "funding": "https://github.com/sponsors/Fdawgs",
49
49
  "engines": {
50
- "node": ">=18"
50
+ "node": ">=20"
51
51
  },
52
52
  "dependencies": {
53
53
  "camelcase": "^6.3.0",
54
- "semver": "^7.6.3",
55
- "upath": "^2.0.1"
54
+ "semver": "^7.6.3"
56
55
  }
57
56
  }
package/src/index.js CHANGED
@@ -4,7 +4,7 @@ const { execFile, spawn, spawnSync } = require("node:child_process");
4
4
  const { promisify } = require("node:util");
5
5
  const camelCase = require("camelcase");
6
6
  const { lt } = require("semver");
7
- const { joinSafe, normalizeTrim } = require("upath");
7
+ const { normalize, resolve: pathResolve } = require("node:path");
8
8
 
9
9
  const execFileAsync = promisify(execFile);
10
10
 
@@ -22,13 +22,25 @@ 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 {object} acceptedOptions - Object containing accepted options.
31
- * @param {object} options - Object containing options to pass to binary.
42
+ * @param {PopplerAcceptedOptions} acceptedOptions - Object containing accepted options.
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.
34
46
  * @throws If invalid arguments provided.
@@ -38,45 +50,49 @@ function parseOptions(acceptedOptions, options, version) {
38
50
  const args = [];
39
51
  /** @type {string[]} */
40
52
  const invalidArgs = [];
41
- Object.keys(options).forEach((key) => {
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)) {
58
+ const option = options[key];
59
+ const acceptedOption = acceptedOptions[key];
60
+
43
61
  // eslint-disable-next-line valid-typeof -- `type` is a string
44
- if (acceptedOptions[key].type === typeof options[key]) {
62
+ if (acceptedOption.type === typeof option) {
45
63
  // Skip boolean options if false
46
- if (acceptedOptions[key].type === "boolean" && !options[key]) {
47
- return;
48
- }
49
-
50
- // Arg will be empty for some non-standard options
51
- if (acceptedOptions[key].arg !== "") {
52
- args.push(acceptedOptions[key].arg);
53
- }
64
+ if (acceptedOption.type !== "boolean" || option) {
65
+ // Arg will be empty for some non-standard options
66
+ if (acceptedOption.arg !== "") {
67
+ args.push(acceptedOption.arg);
68
+ }
54
69
 
55
- if (typeof options[key] !== "boolean") {
56
- args.push(options[key]);
70
+ if (typeof option !== "boolean") {
71
+ args.push(option);
72
+ }
57
73
  }
58
74
  } else {
59
75
  invalidArgs.push(
60
76
  `Invalid value type provided for option '${key}', expected ${
61
- acceptedOptions[key].type
62
- } but received ${typeof options[key]}`
77
+ acceptedOption.type
78
+ } but received ${typeof option}`
63
79
  );
64
80
  }
65
81
 
66
82
  if (
67
- acceptedOptions[key].minVersion &&
83
+ acceptedOption.minVersion &&
68
84
  version &&
69
85
  // @ts-ignore: type checking is done above
70
- lt(version, acceptedOptions[key].minVersion, { loose: true })
86
+ lt(version, acceptedOption.minVersion, { loose: true })
71
87
  ) {
72
88
  invalidArgs.push(
73
- `Invalid option provided for the current version of the binary used. '${key}' was introduced in v${acceptedOptions[key].minVersion}, but received v${version}`
89
+ `Invalid option provided for the current version of the binary used. '${key}' was introduced in v${acceptedOption.minVersion}, but received v${version}`
74
90
  );
75
91
  }
76
92
  } else {
77
93
  invalidArgs.push(`Invalid option provided '${key}'`);
78
94
  }
79
- });
95
+ }
80
96
  if (invalidArgs.length === 0) {
81
97
  return args;
82
98
  }
@@ -84,6 +100,8 @@ function parseOptions(acceptedOptions, options, version) {
84
100
  }
85
101
 
86
102
  class Poppler {
103
+ #popplerPath;
104
+
87
105
  /**
88
106
  * @param {string} [binPath] - Path of poppler-utils binaries.
89
107
  * If not provided, the constructor will attempt to find the Poppler `pdfinfo` binary
@@ -92,12 +110,12 @@ class Poppler {
92
110
  * if a local installation is not found.
93
111
  */
94
112
  constructor(binPath) {
95
- this.popplerPath = "";
113
+ this.#popplerPath = "";
96
114
 
97
115
  /* istanbul ignore else: requires specific OS */
98
116
  if (binPath) {
99
117
  /** @type {string|undefined} */
100
- this.popplerPath = binPath;
118
+ this.#popplerPath = binPath;
101
119
  } else {
102
120
  const { platform } = process;
103
121
 
@@ -107,10 +125,10 @@ class Poppler {
107
125
  const popplerPath = /(.+)pdfinfo/u.exec(which)?.[1];
108
126
 
109
127
  if (popplerPath) {
110
- this.popplerPath = popplerPath;
128
+ this.#popplerPath = popplerPath;
111
129
  }
112
130
  if (platform === "win32" && !popplerPath) {
113
- this.popplerPath = joinSafe(
131
+ this.#popplerPath = pathResolve(
114
132
  __dirname,
115
133
  "lib",
116
134
  "win32",
@@ -122,12 +140,20 @@ class Poppler {
122
140
  }
123
141
 
124
142
  /* istanbul ignore next: unable to test due to https://github.com/jestjs/jest/pull/14297 */
125
- if (!this.popplerPath) {
143
+ if (!this.#popplerPath) {
126
144
  throw new Error(
127
145
  `Unable to find ${process.platform} Poppler binaries, please pass the installation directory as a parameter to the Poppler instance.`
128
146
  );
129
147
  }
130
- this.popplerPath = normalizeTrim(this.popplerPath);
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;
131
157
  }
132
158
 
133
159
  /**
@@ -142,6 +168,7 @@ class Poppler {
142
168
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
143
169
  */
144
170
  async pdfAttach(file, fileToAttach, outputFile, options = {}) {
171
+ /** @type {PopplerAcceptedOptions} */
145
172
  const acceptedOptions = {
146
173
  printVersionInfo: { arg: "-v", type: "boolean" },
147
174
  replace: { arg: "-replace", type: "boolean" },
@@ -152,7 +179,7 @@ class Poppler {
152
179
  args.push(file, fileToAttach, outputFile);
153
180
 
154
181
  const { stdout } = await execFileAsync(
155
- joinSafe(this.popplerPath, "pdfattach"),
182
+ pathResolve(this.#popplerPath, "pdfattach"),
156
183
  args
157
184
  );
158
185
  return Promise.resolve(stdout);
@@ -188,6 +215,7 @@ class Poppler {
188
215
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
189
216
  */
190
217
  async pdfDetach(file, options = {}) {
218
+ /** @type {PopplerAcceptedOptions} */
191
219
  const acceptedOptions = {
192
220
  listEmbedded: { arg: "-list", type: "boolean" },
193
221
  outputEncoding: { arg: "-enc", type: "string" },
@@ -209,7 +237,7 @@ class Poppler {
209
237
  args.push(file);
210
238
 
211
239
  const { stdout } = await execFileAsync(
212
- joinSafe(this.popplerPath, "pdfdetach"),
240
+ pathResolve(this.#popplerPath, "pdfdetach"),
213
241
  args
214
242
  );
215
243
  return Promise.resolve(stdout);
@@ -221,7 +249,7 @@ class Poppler {
221
249
  /**
222
250
  * @author Frazer Smith
223
251
  * @description Lists the fonts used in a PDF file along with various information for each font.
224
- * @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.
225
253
  * @param {object} [options] - Object containing options to pass to binary.
226
254
  * @param {number} [options.firstPageToExamine] - Specifies the first page to examine.
227
255
  * @param {number} [options.lastPageToExamine] - Specifies the last page to examine.
@@ -233,6 +261,7 @@ class Poppler {
233
261
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
234
262
  */
235
263
  async pdfFonts(file, options = {}) {
264
+ /** @type {PopplerAcceptedOptions} */
236
265
  const acceptedOptions = {
237
266
  firstPageToExamine: { arg: "-f", type: "number" },
238
267
  lastPageToExamine: { arg: "-l", type: "number" },
@@ -244,7 +273,7 @@ class Poppler {
244
273
 
245
274
  try {
246
275
  const { stderr } = await execFileAsync(
247
- joinSafe(this.popplerPath, "pdffonts"),
276
+ pathResolve(this.#popplerPath, "pdffonts"),
248
277
  ["-v"]
249
278
  );
250
279
 
@@ -257,7 +286,7 @@ class Poppler {
257
286
  args.push(Buffer.isBuffer(file) ? "-" : file);
258
287
 
259
288
  const child = spawn(
260
- joinSafe(this.popplerPath, "pdffonts"),
289
+ pathResolve(this.#popplerPath, "pdffonts"),
261
290
  args
262
291
  );
263
292
 
@@ -288,6 +317,7 @@ class Poppler {
288
317
  } else {
289
318
  reject(
290
319
  new Error(
320
+ // @ts-ignore: Second operand used if code is not in errorMessages
291
321
  errorMessages[code] ||
292
322
  `pdffonts ${args.join(
293
323
  " "
@@ -305,7 +335,7 @@ class Poppler {
305
335
  /**
306
336
  * @author Frazer Smith
307
337
  * @description Saves images from a PDF file as PPM, PBM, PNG, TIFF, JPEG, JPEG2000, or JBIG2 files.
308
- * @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.
309
339
  * @param {string} [outputPrefix] - Filename prefix of output files.
310
340
  * @param {object} [options] - Object containing options to pass to binary.
311
341
  * @param {boolean} [options.allFiles] - Write JPEG, JPEG2000, JBIG2, and CCITT images in their native format.
@@ -327,6 +357,7 @@ class Poppler {
327
357
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
328
358
  */
329
359
  async pdfImages(file, outputPrefix, options = {}) {
360
+ /** @type {PopplerAcceptedOptions} */
330
361
  const acceptedOptions = {
331
362
  allFiles: { arg: "-all", type: "boolean" },
332
363
  ccittFile: { arg: "-ccitt", type: "boolean" },
@@ -345,7 +376,7 @@ class Poppler {
345
376
 
346
377
  try {
347
378
  const { stderr } = await execFileAsync(
348
- joinSafe(this.popplerPath, "pdfimages"),
379
+ pathResolve(this.#popplerPath, "pdfimages"),
349
380
  ["-v"]
350
381
  );
351
382
 
@@ -362,7 +393,7 @@ class Poppler {
362
393
  }
363
394
 
364
395
  const child = spawn(
365
- joinSafe(this.popplerPath, "pdfimages"),
396
+ pathResolve(this.#popplerPath, "pdfimages"),
366
397
  args
367
398
  );
368
399
 
@@ -393,6 +424,7 @@ class Poppler {
393
424
  } else {
394
425
  reject(
395
426
  new Error(
427
+ // @ts-ignore: Second operand used if code is not in errorMessages
396
428
  errorMessages[code] ||
397
429
  `pdfimages ${args.join(
398
430
  " "
@@ -410,7 +442,7 @@ class Poppler {
410
442
  /**
411
443
  * @author Frazer Smith
412
444
  * @description Prints the contents of the `Info` dictionary from a PDF file.
413
- * @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.
414
446
  * @param {object} [options] - Object containing options to pass to binary.
415
447
  * @param {number} [options.firstPageToConvert] - First page to print.
416
448
  * @param {number} [options.lastPageToConvert] - Last page to print.
@@ -442,6 +474,7 @@ class Poppler {
442
474
  * `options.printAsJson` is `true`, or rejects with an `Error` object.
443
475
  */
444
476
  async pdfInfo(file, options = {}) {
477
+ /** @type {PopplerAcceptedOptions} */
445
478
  const acceptedOptions = {
446
479
  firstPageToConvert: { arg: "-f", type: "number" },
447
480
  lastPageToConvert: { arg: "-l", type: "number" },
@@ -464,7 +497,7 @@ class Poppler {
464
497
 
465
498
  try {
466
499
  const { stderr } = await execFileAsync(
467
- joinSafe(this.popplerPath, "pdfinfo"),
500
+ pathResolve(this.#popplerPath, "pdfinfo"),
468
501
  ["-v"]
469
502
  );
470
503
 
@@ -489,7 +522,7 @@ class Poppler {
489
522
  }
490
523
 
491
524
  const child = spawn(
492
- joinSafe(this.popplerPath, "pdfinfo"),
525
+ pathResolve(this.#popplerPath, "pdfinfo"),
493
526
  args
494
527
  );
495
528
 
@@ -525,13 +558,16 @@ class Poppler {
525
558
  */
526
559
  if (options.printAsJson === true) {
527
560
  const info = {};
528
- stdOut.split("\n").forEach((line) => {
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];
529
565
  const lines = line.split(": ");
530
566
  if (lines.length > 1) {
531
567
  // @ts-ignore: creating dynamic object keys
532
568
  info[camelCase(lines[0])] = lines[1].trim();
533
569
  }
534
- });
570
+ }
535
571
  resolve(info);
536
572
  } else {
537
573
  resolve(stdOut.trim());
@@ -543,6 +579,7 @@ class Poppler {
543
579
  } else {
544
580
  reject(
545
581
  new Error(
582
+ // @ts-ignore: Second operand used if code is not in errorMessages
546
583
  errorMessages[code] ||
547
584
  `pdfinfo ${args.join(
548
585
  " "
@@ -575,6 +612,7 @@ class Poppler {
575
612
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
576
613
  */
577
614
  async pdfSeparate(file, outputPattern, options = {}) {
615
+ /** @type {PopplerAcceptedOptions} */
578
616
  const acceptedOptions = {
579
617
  firstPageToExtract: { arg: "-f", type: "number" },
580
618
  lastPageToExtract: { arg: "-l", type: "number" },
@@ -583,7 +621,7 @@ class Poppler {
583
621
 
584
622
  try {
585
623
  const { stderr } = await execFileAsync(
586
- joinSafe(this.popplerPath, "pdfseparate"),
624
+ pathResolve(this.#popplerPath, "pdfseparate"),
587
625
  ["-v"]
588
626
  );
589
627
 
@@ -594,7 +632,7 @@ class Poppler {
594
632
  args.push(file, outputPattern);
595
633
 
596
634
  const { stdout } = await execFileAsync(
597
- joinSafe(this.popplerPath, "pdfseparate"),
635
+ pathResolve(this.#popplerPath, "pdfseparate"),
598
636
  args
599
637
  );
600
638
  return Promise.resolve(stdout);
@@ -711,6 +749,7 @@ class Poppler {
711
749
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
712
750
  */
713
751
  async pdfToCairo(file, outputFile, options = {}) {
752
+ /** @type {PopplerAcceptedOptions} */
714
753
  const acceptedOptions = {
715
754
  antialias: { arg: "-antialias", type: "string" },
716
755
  cropBox: { arg: "-cropbox", type: "boolean" },
@@ -767,7 +806,7 @@ class Poppler {
767
806
 
768
807
  try {
769
808
  const { stderr } = await execFileAsync(
770
- joinSafe(this.popplerPath, "pdftocairo"),
809
+ pathResolve(this.#popplerPath, "pdftocairo"),
771
810
  ["-v"]
772
811
  );
773
812
 
@@ -783,7 +822,7 @@ class Poppler {
783
822
  );
784
823
 
785
824
  const child = spawn(
786
- joinSafe(this.popplerPath, "pdftocairo"),
825
+ pathResolve(this.#popplerPath, "pdftocairo"),
787
826
  args
788
827
  );
789
828
 
@@ -821,6 +860,7 @@ class Poppler {
821
860
  } else {
822
861
  reject(
823
862
  new Error(
863
+ // @ts-ignore: Second operand used if code is not in errorMessages
824
864
  errorMessages[code] ||
825
865
  `pdftocairo ${args.join(
826
866
  " "
@@ -838,7 +878,7 @@ class Poppler {
838
878
  /**
839
879
  * @author Frazer Smith
840
880
  * @description Converts a PDF file to HTML.
841
- * @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.
842
882
  * @param {string} [outputFile] - Filepath of the file to output the results to.
843
883
  * If `undefined` then Poppler will use the directory and name of the original file
844
884
  * and create a new file, with `-html` appended to the end of the filename.
@@ -876,6 +916,7 @@ class Poppler {
876
916
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
877
917
  */
878
918
  async pdfToHtml(file, outputFile, options = {}) {
919
+ /** @type {PopplerAcceptedOptions} */
879
920
  const acceptedOptions = {
880
921
  complexOutput: { arg: "-c", type: "boolean" },
881
922
  dataUrls: {
@@ -908,7 +949,7 @@ class Poppler {
908
949
 
909
950
  try {
910
951
  const { stderr } = await execFileAsync(
911
- joinSafe(this.popplerPath, "pdftohtml"),
952
+ pathResolve(this.#popplerPath, "pdftohtml"),
912
953
  ["-v"]
913
954
  );
914
955
 
@@ -925,7 +966,7 @@ class Poppler {
925
966
  }
926
967
 
927
968
  const child = spawn(
928
- joinSafe(this.popplerPath, "pdftohtml"),
969
+ pathResolve(this.#popplerPath, "pdftohtml"),
929
970
  args
930
971
  );
931
972
 
@@ -967,7 +1008,7 @@ class Poppler {
967
1008
  * @description Converts a PDF file to colour image files in Portable Pixmap (PPM) format,
968
1009
  * grayscale image files in Portable Graymap (PGM) format, or monochrome image files
969
1010
  * in Portable Bitmap (PBM) format.
970
- * @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.
971
1012
  * @param {string} outputPath - Filepath to output the results to.
972
1013
  * @param {object} [options] - Object containing options to pass to binary.
973
1014
  * @param {('no'|'yes')} [options.antialiasFonts] - Enable or disable font anti-aliasing.
@@ -1037,6 +1078,7 @@ class Poppler {
1037
1078
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
1038
1079
  */
1039
1080
  async pdfToPpm(file, outputPath, options = {}) {
1081
+ /** @type {PopplerAcceptedOptions} */
1040
1082
  const acceptedOptions = {
1041
1083
  antialiasFonts: { arg: "-aa", type: "string" },
1042
1084
  antialiasVectors: { arg: "-aaVector", type: "string" },
@@ -1109,7 +1151,7 @@ class Poppler {
1109
1151
 
1110
1152
  try {
1111
1153
  const { stderr } = await execFileAsync(
1112
- joinSafe(this.popplerPath, "pdftoppm"),
1154
+ pathResolve(this.#popplerPath, "pdftoppm"),
1113
1155
  ["-v"]
1114
1156
  );
1115
1157
 
@@ -1122,7 +1164,7 @@ class Poppler {
1122
1164
  args.push(Buffer.isBuffer(file) ? "-" : file, outputPath);
1123
1165
 
1124
1166
  const child = spawn(
1125
- joinSafe(this.popplerPath, "pdftoppm"),
1167
+ pathResolve(this.#popplerPath, "pdftoppm"),
1126
1168
  args
1127
1169
  );
1128
1170
 
@@ -1146,6 +1188,7 @@ class Poppler {
1146
1188
  } else {
1147
1189
  reject(
1148
1190
  new Error(
1191
+ // @ts-ignore: Second operand used if code is not in errorMessages
1149
1192
  errorMessages[code] ||
1150
1193
  `pdftoppm ${args.join(
1151
1194
  " "
@@ -1163,7 +1206,7 @@ class Poppler {
1163
1206
  /**
1164
1207
  * @author Frazer Smith
1165
1208
  * @description Converts a PDF file to PostScript (PS).
1166
- * @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.
1167
1210
  * @param {string} [outputFile] - Filepath of the file to output the results to.
1168
1211
  * If `undefined` then will write output to stdout.
1169
1212
  * @param {object} [options] - Object containing options to pass to binary.
@@ -1270,6 +1313,7 @@ class Poppler {
1270
1313
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
1271
1314
  */
1272
1315
  async pdfToPs(file, outputFile, options = {}) {
1316
+ /** @type {PopplerAcceptedOptions} */
1273
1317
  const acceptedOptions = {
1274
1318
  antialias: { arg: "-aaRaster", type: "string" },
1275
1319
  binary: { arg: "-binary", type: "boolean" },
@@ -1341,7 +1385,7 @@ class Poppler {
1341
1385
 
1342
1386
  try {
1343
1387
  const { stderr } = await execFileAsync(
1344
- joinSafe(this.popplerPath, "pdftops"),
1388
+ pathResolve(this.#popplerPath, "pdftops"),
1345
1389
  ["-v"]
1346
1390
  );
1347
1391
 
@@ -1357,7 +1401,7 @@ class Poppler {
1357
1401
  );
1358
1402
 
1359
1403
  const child = spawn(
1360
- joinSafe(this.popplerPath, "pdftops"),
1404
+ pathResolve(this.#popplerPath, "pdftops"),
1361
1405
  args
1362
1406
  );
1363
1407
 
@@ -1388,6 +1432,7 @@ class Poppler {
1388
1432
  } else {
1389
1433
  reject(
1390
1434
  new Error(
1435
+ // @ts-ignore: Second operand used if code is not in errorMessages
1391
1436
  errorMessages[code] ||
1392
1437
  `pdftops ${args.join(
1393
1438
  " "
@@ -1405,7 +1450,7 @@ class Poppler {
1405
1450
  /**
1406
1451
  * @author Frazer Smith
1407
1452
  * @description Converts a PDF file to TXT.
1408
- * @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.
1409
1454
  * @param {string} [outputFile] - Filepath of the file to output the results to.
1410
1455
  * If `undefined` then will write output to stdout.
1411
1456
  * @param {object} [options] - Object containing options to pass to binary.
@@ -1451,6 +1496,7 @@ class Poppler {
1451
1496
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
1452
1497
  */
1453
1498
  async pdfToText(file, outputFile, options = {}) {
1499
+ /** @type {PopplerAcceptedOptions} */
1454
1500
  const acceptedOptions = {
1455
1501
  boundingBoxXhtml: { arg: "-bbox", type: "boolean" },
1456
1502
  boundingBoxXhtmlLayout: {
@@ -1491,7 +1537,7 @@ class Poppler {
1491
1537
 
1492
1538
  try {
1493
1539
  const { stderr } = await execFileAsync(
1494
- joinSafe(this.popplerPath, "pdftotext"),
1540
+ pathResolve(this.#popplerPath, "pdftotext"),
1495
1541
  ["-v"]
1496
1542
  );
1497
1543
 
@@ -1507,7 +1553,7 @@ class Poppler {
1507
1553
  );
1508
1554
 
1509
1555
  const child = spawn(
1510
- joinSafe(this.popplerPath, "pdftotext"),
1556
+ pathResolve(this.#popplerPath, "pdftotext"),
1511
1557
  args
1512
1558
  );
1513
1559
 
@@ -1540,6 +1586,7 @@ class Poppler {
1540
1586
  } else {
1541
1587
  reject(
1542
1588
  new Error(
1589
+ // @ts-ignore: Second operand used if code is not in errorMessages
1543
1590
  errorMessages[code] ||
1544
1591
  `pdftotext ${args.join(
1545
1592
  " "
@@ -1566,13 +1613,14 @@ class Poppler {
1566
1613
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
1567
1614
  */
1568
1615
  async pdfUnite(files, outputFile, options = {}) {
1616
+ /** @type {PopplerAcceptedOptions} */
1569
1617
  const acceptedOptions = {
1570
1618
  printVersionInfo: { arg: "-v", type: "boolean" },
1571
1619
  };
1572
1620
 
1573
1621
  try {
1574
1622
  const { stderr } = await execFileAsync(
1575
- joinSafe(this.popplerPath, "pdfunite"),
1623
+ pathResolve(this.#popplerPath, "pdfunite"),
1576
1624
  ["-v"]
1577
1625
  );
1578
1626
 
@@ -1580,13 +1628,10 @@ class Poppler {
1580
1628
  const versionInfo = popplerVersionRegex.exec(stderr)[1];
1581
1629
 
1582
1630
  const args = parseOptions(acceptedOptions, options, versionInfo);
1583
- files.forEach((element) => {
1584
- args.push(element);
1585
- });
1586
- args.push(outputFile);
1631
+ args.push(...files, outputFile);
1587
1632
 
1588
1633
  const { stdout } = await execFileAsync(
1589
- joinSafe(this.popplerPath, "pdfunite"),
1634
+ pathResolve(this.#popplerPath, "pdfunite"),
1590
1635
  args
1591
1636
  );
1592
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
- popplerPath: string;
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?: ("best" | "default" | "fast" | "good" | "gray" | "none" | "subpixel");
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?: ("A3" | "A4" | "legal" | "letter" | "match");
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?: ("deflate" | "jpeg" | "lzw" | "none" | "packbits");
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?: ("JPG" | "PNG");
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?: ("no" | "yes");
497
- antialiasVectors?: ("no" | "yes");
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?: ("no" | "yes");
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?: ("none" | "shape" | "solid");
532
- tiffCompression?: ("deflate" | "jpeg" | "lzw" | "none" | "packbits");
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?: ("no" | "yes");
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?: ("A3" | "A4" | "legal" | "letter" | "match");
677
- paperWidth?: number;
678
- passfonts?: boolean;
679
- preload?: boolean;
680
- printVersionInfo?: boolean;
681
- processColorFormat?: ("CMYK8" | "MONO8" | "RGB8");
682
- processColorProfile?: string;
683
- quiet?: boolean;
684
- rasterize?: ("always" | "never" | "whenneeded");
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?: ("dos" | "mac" | "unix");
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
  }