node-poppler 7.2.4 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-poppler",
3
- "version": "7.2.4",
4
- "description": "Asynchronous node.js wrapper for the Poppler PDF rendering library",
3
+ "version": "8.0.1",
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": ">=18"
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 {object} acceptedOptions - Object containing accepted options.
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,9 +50,17 @@ function parseOptions(acceptedOptions, options, version) {
38
50
  const args = [];
39
51
  /** @type {string[]} */
40
52
  const invalidArgs = [];
41
- for (const key of Object.keys(options)) {
53
+ /**
54
+ * Imperative loops are faster than functional loops.
55
+ * @see {@link https://romgrk.com/posts/optimizing-javascript#3-avoid-arrayobject-methods || Optimizing JavaScript}
56
+ */
57
+ const entries = Object.entries(options);
58
+ const entriesLength = entries.length;
59
+ for (let i = 0; i < entriesLength; i += 1) {
60
+ // Destructuring adds overhead, so use index access
61
+ const key = entries[i][0];
42
62
  if (Object.hasOwn(acceptedOptions, key)) {
43
- const option = options[key];
63
+ const option = entries[i][1];
44
64
  const acceptedOption = acceptedOptions[key];
45
65
 
46
66
  // eslint-disable-next-line valid-typeof -- `type` is a string
@@ -85,6 +105,8 @@ function parseOptions(acceptedOptions, options, version) {
85
105
  }
86
106
 
87
107
  class Poppler {
108
+ #popplerPath;
109
+
88
110
  /**
89
111
  * @param {string} [binPath] - Path of poppler-utils binaries.
90
112
  * If not provided, the constructor will attempt to find the Poppler `pdfinfo` binary
@@ -93,12 +115,12 @@ class Poppler {
93
115
  * if a local installation is not found.
94
116
  */
95
117
  constructor(binPath) {
96
- this.popplerPath = "";
118
+ this.#popplerPath = "";
97
119
 
98
120
  /* istanbul ignore else: requires specific OS */
99
121
  if (binPath) {
100
122
  /** @type {string|undefined} */
101
- this.popplerPath = binPath;
123
+ this.#popplerPath = binPath;
102
124
  } else {
103
125
  const { platform } = process;
104
126
 
@@ -108,10 +130,10 @@ class Poppler {
108
130
  const popplerPath = /(.+)pdfinfo/u.exec(which)?.[1];
109
131
 
110
132
  if (popplerPath) {
111
- this.popplerPath = popplerPath;
133
+ this.#popplerPath = popplerPath;
112
134
  }
113
135
  if (platform === "win32" && !popplerPath) {
114
- this.popplerPath = pathResolve(
136
+ this.#popplerPath = pathResolve(
115
137
  __dirname,
116
138
  "lib",
117
139
  "win32",
@@ -123,12 +145,20 @@ class Poppler {
123
145
  }
124
146
 
125
147
  /* istanbul ignore next: unable to test due to https://github.com/jestjs/jest/pull/14297 */
126
- if (!this.popplerPath) {
148
+ if (!this.#popplerPath) {
127
149
  throw new Error(
128
150
  `Unable to find ${process.platform} Poppler binaries, please pass the installation directory as a parameter to the Poppler instance.`
129
151
  );
130
152
  }
131
- this.popplerPath = normalize(this.popplerPath);
153
+ this.#popplerPath = normalize(this.#popplerPath);
154
+ }
155
+
156
+ /**
157
+ * @description Returns the path of the Poppler binaries.
158
+ * @returns {string} Path of Poppler binaries.
159
+ */
160
+ get path() {
161
+ return this.#popplerPath;
132
162
  }
133
163
 
134
164
  /**
@@ -143,6 +173,7 @@ class Poppler {
143
173
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
144
174
  */
145
175
  async pdfAttach(file, fileToAttach, outputFile, options = {}) {
176
+ /** @type {PopplerAcceptedOptions} */
146
177
  const acceptedOptions = {
147
178
  printVersionInfo: { arg: "-v", type: "boolean" },
148
179
  replace: { arg: "-replace", type: "boolean" },
@@ -153,7 +184,7 @@ class Poppler {
153
184
  args.push(file, fileToAttach, outputFile);
154
185
 
155
186
  const { stdout } = await execFileAsync(
156
- pathResolve(this.popplerPath, "pdfattach"),
187
+ pathResolve(this.#popplerPath, "pdfattach"),
157
188
  args
158
189
  );
159
190
  return Promise.resolve(stdout);
@@ -189,6 +220,7 @@ class Poppler {
189
220
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
190
221
  */
191
222
  async pdfDetach(file, options = {}) {
223
+ /** @type {PopplerAcceptedOptions} */
192
224
  const acceptedOptions = {
193
225
  listEmbedded: { arg: "-list", type: "boolean" },
194
226
  outputEncoding: { arg: "-enc", type: "string" },
@@ -210,7 +242,7 @@ class Poppler {
210
242
  args.push(file);
211
243
 
212
244
  const { stdout } = await execFileAsync(
213
- pathResolve(this.popplerPath, "pdfdetach"),
245
+ pathResolve(this.#popplerPath, "pdfdetach"),
214
246
  args
215
247
  );
216
248
  return Promise.resolve(stdout);
@@ -222,7 +254,7 @@ class Poppler {
222
254
  /**
223
255
  * @author Frazer Smith
224
256
  * @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.
257
+ * @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
226
258
  * @param {object} [options] - Object containing options to pass to binary.
227
259
  * @param {number} [options.firstPageToExamine] - Specifies the first page to examine.
228
260
  * @param {number} [options.lastPageToExamine] - Specifies the last page to examine.
@@ -234,6 +266,7 @@ class Poppler {
234
266
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
235
267
  */
236
268
  async pdfFonts(file, options = {}) {
269
+ /** @type {PopplerAcceptedOptions} */
237
270
  const acceptedOptions = {
238
271
  firstPageToExamine: { arg: "-f", type: "number" },
239
272
  lastPageToExamine: { arg: "-l", type: "number" },
@@ -245,7 +278,7 @@ class Poppler {
245
278
 
246
279
  try {
247
280
  const { stderr } = await execFileAsync(
248
- pathResolve(this.popplerPath, "pdffonts"),
281
+ pathResolve(this.#popplerPath, "pdffonts"),
249
282
  ["-v"]
250
283
  );
251
284
 
@@ -258,7 +291,7 @@ class Poppler {
258
291
  args.push(Buffer.isBuffer(file) ? "-" : file);
259
292
 
260
293
  const child = spawn(
261
- pathResolve(this.popplerPath, "pdffonts"),
294
+ pathResolve(this.#popplerPath, "pdffonts"),
262
295
  args
263
296
  );
264
297
 
@@ -289,6 +322,7 @@ class Poppler {
289
322
  } else {
290
323
  reject(
291
324
  new Error(
325
+ // @ts-ignore: Second operand used if code is not in errorMessages
292
326
  errorMessages[code] ||
293
327
  `pdffonts ${args.join(
294
328
  " "
@@ -306,7 +340,7 @@ class Poppler {
306
340
  /**
307
341
  * @author Frazer Smith
308
342
  * @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.
343
+ * @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
310
344
  * @param {string} [outputPrefix] - Filename prefix of output files.
311
345
  * @param {object} [options] - Object containing options to pass to binary.
312
346
  * @param {boolean} [options.allFiles] - Write JPEG, JPEG2000, JBIG2, and CCITT images in their native format.
@@ -328,6 +362,7 @@ class Poppler {
328
362
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
329
363
  */
330
364
  async pdfImages(file, outputPrefix, options = {}) {
365
+ /** @type {PopplerAcceptedOptions} */
331
366
  const acceptedOptions = {
332
367
  allFiles: { arg: "-all", type: "boolean" },
333
368
  ccittFile: { arg: "-ccitt", type: "boolean" },
@@ -346,7 +381,7 @@ class Poppler {
346
381
 
347
382
  try {
348
383
  const { stderr } = await execFileAsync(
349
- pathResolve(this.popplerPath, "pdfimages"),
384
+ pathResolve(this.#popplerPath, "pdfimages"),
350
385
  ["-v"]
351
386
  );
352
387
 
@@ -363,7 +398,7 @@ class Poppler {
363
398
  }
364
399
 
365
400
  const child = spawn(
366
- pathResolve(this.popplerPath, "pdfimages"),
401
+ pathResolve(this.#popplerPath, "pdfimages"),
367
402
  args
368
403
  );
369
404
 
@@ -394,6 +429,7 @@ class Poppler {
394
429
  } else {
395
430
  reject(
396
431
  new Error(
432
+ // @ts-ignore: Second operand used if code is not in errorMessages
397
433
  errorMessages[code] ||
398
434
  `pdfimages ${args.join(
399
435
  " "
@@ -411,7 +447,7 @@ class Poppler {
411
447
  /**
412
448
  * @author Frazer Smith
413
449
  * @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.
450
+ * @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
415
451
  * @param {object} [options] - Object containing options to pass to binary.
416
452
  * @param {number} [options.firstPageToConvert] - First page to print.
417
453
  * @param {number} [options.lastPageToConvert] - Last page to print.
@@ -443,6 +479,7 @@ class Poppler {
443
479
  * `options.printAsJson` is `true`, or rejects with an `Error` object.
444
480
  */
445
481
  async pdfInfo(file, options = {}) {
482
+ /** @type {PopplerAcceptedOptions} */
446
483
  const acceptedOptions = {
447
484
  firstPageToConvert: { arg: "-f", type: "number" },
448
485
  lastPageToConvert: { arg: "-l", type: "number" },
@@ -465,7 +502,7 @@ class Poppler {
465
502
 
466
503
  try {
467
504
  const { stderr } = await execFileAsync(
468
- pathResolve(this.popplerPath, "pdfinfo"),
505
+ pathResolve(this.#popplerPath, "pdfinfo"),
469
506
  ["-v"]
470
507
  );
471
508
 
@@ -490,7 +527,7 @@ class Poppler {
490
527
  }
491
528
 
492
529
  const child = spawn(
493
- pathResolve(this.popplerPath, "pdfinfo"),
530
+ pathResolve(this.#popplerPath, "pdfinfo"),
494
531
  args
495
532
  );
496
533
 
@@ -526,13 +563,16 @@ class Poppler {
526
563
  */
527
564
  if (options.printAsJson === true) {
528
565
  const info = {};
529
- stdOut.split("\n").forEach((line) => {
566
+ const stdOutLines = stdOut.split("\n");
567
+ const stdOutLinesLength = stdOutLines.length;
568
+ for (let i = 0; i < stdOutLinesLength; i += 1) {
569
+ const line = stdOutLines[i];
530
570
  const lines = line.split(": ");
531
571
  if (lines.length > 1) {
532
572
  // @ts-ignore: creating dynamic object keys
533
573
  info[camelCase(lines[0])] = lines[1].trim();
534
574
  }
535
- });
575
+ }
536
576
  resolve(info);
537
577
  } else {
538
578
  resolve(stdOut.trim());
@@ -544,6 +584,7 @@ class Poppler {
544
584
  } else {
545
585
  reject(
546
586
  new Error(
587
+ // @ts-ignore: Second operand used if code is not in errorMessages
547
588
  errorMessages[code] ||
548
589
  `pdfinfo ${args.join(
549
590
  " "
@@ -576,6 +617,7 @@ class Poppler {
576
617
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
577
618
  */
578
619
  async pdfSeparate(file, outputPattern, options = {}) {
620
+ /** @type {PopplerAcceptedOptions} */
579
621
  const acceptedOptions = {
580
622
  firstPageToExtract: { arg: "-f", type: "number" },
581
623
  lastPageToExtract: { arg: "-l", type: "number" },
@@ -584,7 +626,7 @@ class Poppler {
584
626
 
585
627
  try {
586
628
  const { stderr } = await execFileAsync(
587
- pathResolve(this.popplerPath, "pdfseparate"),
629
+ pathResolve(this.#popplerPath, "pdfseparate"),
588
630
  ["-v"]
589
631
  );
590
632
 
@@ -595,7 +637,7 @@ class Poppler {
595
637
  args.push(file, outputPattern);
596
638
 
597
639
  const { stdout } = await execFileAsync(
598
- pathResolve(this.popplerPath, "pdfseparate"),
640
+ pathResolve(this.#popplerPath, "pdfseparate"),
599
641
  args
600
642
  );
601
643
  return Promise.resolve(stdout);
@@ -712,6 +754,7 @@ class Poppler {
712
754
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
713
755
  */
714
756
  async pdfToCairo(file, outputFile, options = {}) {
757
+ /** @type {PopplerAcceptedOptions} */
715
758
  const acceptedOptions = {
716
759
  antialias: { arg: "-antialias", type: "string" },
717
760
  cropBox: { arg: "-cropbox", type: "boolean" },
@@ -768,7 +811,7 @@ class Poppler {
768
811
 
769
812
  try {
770
813
  const { stderr } = await execFileAsync(
771
- pathResolve(this.popplerPath, "pdftocairo"),
814
+ pathResolve(this.#popplerPath, "pdftocairo"),
772
815
  ["-v"]
773
816
  );
774
817
 
@@ -784,7 +827,7 @@ class Poppler {
784
827
  );
785
828
 
786
829
  const child = spawn(
787
- pathResolve(this.popplerPath, "pdftocairo"),
830
+ pathResolve(this.#popplerPath, "pdftocairo"),
788
831
  args
789
832
  );
790
833
 
@@ -822,6 +865,7 @@ class Poppler {
822
865
  } else {
823
866
  reject(
824
867
  new Error(
868
+ // @ts-ignore: Second operand used if code is not in errorMessages
825
869
  errorMessages[code] ||
826
870
  `pdftocairo ${args.join(
827
871
  " "
@@ -839,7 +883,7 @@ class Poppler {
839
883
  /**
840
884
  * @author Frazer Smith
841
885
  * @description Converts a PDF file to HTML.
842
- * @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
886
+ * @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
843
887
  * @param {string} [outputFile] - Filepath of the file to output the results to.
844
888
  * If `undefined` then Poppler will use the directory and name of the original file
845
889
  * and create a new file, with `-html` appended to the end of the filename.
@@ -877,6 +921,7 @@ class Poppler {
877
921
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
878
922
  */
879
923
  async pdfToHtml(file, outputFile, options = {}) {
924
+ /** @type {PopplerAcceptedOptions} */
880
925
  const acceptedOptions = {
881
926
  complexOutput: { arg: "-c", type: "boolean" },
882
927
  dataUrls: {
@@ -909,7 +954,7 @@ class Poppler {
909
954
 
910
955
  try {
911
956
  const { stderr } = await execFileAsync(
912
- pathResolve(this.popplerPath, "pdftohtml"),
957
+ pathResolve(this.#popplerPath, "pdftohtml"),
913
958
  ["-v"]
914
959
  );
915
960
 
@@ -926,7 +971,7 @@ class Poppler {
926
971
  }
927
972
 
928
973
  const child = spawn(
929
- pathResolve(this.popplerPath, "pdftohtml"),
974
+ pathResolve(this.#popplerPath, "pdftohtml"),
930
975
  args
931
976
  );
932
977
 
@@ -968,7 +1013,7 @@ class Poppler {
968
1013
  * @description Converts a PDF file to colour image files in Portable Pixmap (PPM) format,
969
1014
  * grayscale image files in Portable Graymap (PGM) format, or monochrome image files
970
1015
  * in Portable Bitmap (PBM) format.
971
- * @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
1016
+ * @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
972
1017
  * @param {string} outputPath - Filepath to output the results to.
973
1018
  * @param {object} [options] - Object containing options to pass to binary.
974
1019
  * @param {('no'|'yes')} [options.antialiasFonts] - Enable or disable font anti-aliasing.
@@ -1038,6 +1083,7 @@ class Poppler {
1038
1083
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
1039
1084
  */
1040
1085
  async pdfToPpm(file, outputPath, options = {}) {
1086
+ /** @type {PopplerAcceptedOptions} */
1041
1087
  const acceptedOptions = {
1042
1088
  antialiasFonts: { arg: "-aa", type: "string" },
1043
1089
  antialiasVectors: { arg: "-aaVector", type: "string" },
@@ -1110,7 +1156,7 @@ class Poppler {
1110
1156
 
1111
1157
  try {
1112
1158
  const { stderr } = await execFileAsync(
1113
- pathResolve(this.popplerPath, "pdftoppm"),
1159
+ pathResolve(this.#popplerPath, "pdftoppm"),
1114
1160
  ["-v"]
1115
1161
  );
1116
1162
 
@@ -1123,7 +1169,7 @@ class Poppler {
1123
1169
  args.push(Buffer.isBuffer(file) ? "-" : file, outputPath);
1124
1170
 
1125
1171
  const child = spawn(
1126
- pathResolve(this.popplerPath, "pdftoppm"),
1172
+ pathResolve(this.#popplerPath, "pdftoppm"),
1127
1173
  args
1128
1174
  );
1129
1175
 
@@ -1147,6 +1193,7 @@ class Poppler {
1147
1193
  } else {
1148
1194
  reject(
1149
1195
  new Error(
1196
+ // @ts-ignore: Second operand used if code is not in errorMessages
1150
1197
  errorMessages[code] ||
1151
1198
  `pdftoppm ${args.join(
1152
1199
  " "
@@ -1164,7 +1211,7 @@ class Poppler {
1164
1211
  /**
1165
1212
  * @author Frazer Smith
1166
1213
  * @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.
1214
+ * @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
1168
1215
  * @param {string} [outputFile] - Filepath of the file to output the results to.
1169
1216
  * If `undefined` then will write output to stdout.
1170
1217
  * @param {object} [options] - Object containing options to pass to binary.
@@ -1271,6 +1318,7 @@ class Poppler {
1271
1318
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
1272
1319
  */
1273
1320
  async pdfToPs(file, outputFile, options = {}) {
1321
+ /** @type {PopplerAcceptedOptions} */
1274
1322
  const acceptedOptions = {
1275
1323
  antialias: { arg: "-aaRaster", type: "string" },
1276
1324
  binary: { arg: "-binary", type: "boolean" },
@@ -1342,7 +1390,7 @@ class Poppler {
1342
1390
 
1343
1391
  try {
1344
1392
  const { stderr } = await execFileAsync(
1345
- pathResolve(this.popplerPath, "pdftops"),
1393
+ pathResolve(this.#popplerPath, "pdftops"),
1346
1394
  ["-v"]
1347
1395
  );
1348
1396
 
@@ -1358,7 +1406,7 @@ class Poppler {
1358
1406
  );
1359
1407
 
1360
1408
  const child = spawn(
1361
- pathResolve(this.popplerPath, "pdftops"),
1409
+ pathResolve(this.#popplerPath, "pdftops"),
1362
1410
  args
1363
1411
  );
1364
1412
 
@@ -1389,6 +1437,7 @@ class Poppler {
1389
1437
  } else {
1390
1438
  reject(
1391
1439
  new Error(
1440
+ // @ts-ignore: Second operand used if code is not in errorMessages
1392
1441
  errorMessages[code] ||
1393
1442
  `pdftops ${args.join(
1394
1443
  " "
@@ -1406,7 +1455,7 @@ class Poppler {
1406
1455
  /**
1407
1456
  * @author Frazer Smith
1408
1457
  * @description Converts a PDF file to TXT.
1409
- * @param {Buffer|string} file - PDF file as Buffer, or filepath of the PDF file to read.
1458
+ * @param {(Buffer|string)} file - PDF file as Buffer, or filepath of the PDF file to read.
1410
1459
  * @param {string} [outputFile] - Filepath of the file to output the results to.
1411
1460
  * If `undefined` then will write output to stdout.
1412
1461
  * @param {object} [options] - Object containing options to pass to binary.
@@ -1452,6 +1501,7 @@ class Poppler {
1452
1501
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
1453
1502
  */
1454
1503
  async pdfToText(file, outputFile, options = {}) {
1504
+ /** @type {PopplerAcceptedOptions} */
1455
1505
  const acceptedOptions = {
1456
1506
  boundingBoxXhtml: { arg: "-bbox", type: "boolean" },
1457
1507
  boundingBoxXhtmlLayout: {
@@ -1492,7 +1542,7 @@ class Poppler {
1492
1542
 
1493
1543
  try {
1494
1544
  const { stderr } = await execFileAsync(
1495
- pathResolve(this.popplerPath, "pdftotext"),
1545
+ pathResolve(this.#popplerPath, "pdftotext"),
1496
1546
  ["-v"]
1497
1547
  );
1498
1548
 
@@ -1508,7 +1558,7 @@ class Poppler {
1508
1558
  );
1509
1559
 
1510
1560
  const child = spawn(
1511
- pathResolve(this.popplerPath, "pdftotext"),
1561
+ pathResolve(this.#popplerPath, "pdftotext"),
1512
1562
  args
1513
1563
  );
1514
1564
 
@@ -1541,6 +1591,7 @@ class Poppler {
1541
1591
  } else {
1542
1592
  reject(
1543
1593
  new Error(
1594
+ // @ts-ignore: Second operand used if code is not in errorMessages
1544
1595
  errorMessages[code] ||
1545
1596
  `pdftotext ${args.join(
1546
1597
  " "
@@ -1567,13 +1618,14 @@ class Poppler {
1567
1618
  * @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
1568
1619
  */
1569
1620
  async pdfUnite(files, outputFile, options = {}) {
1621
+ /** @type {PopplerAcceptedOptions} */
1570
1622
  const acceptedOptions = {
1571
1623
  printVersionInfo: { arg: "-v", type: "boolean" },
1572
1624
  };
1573
1625
 
1574
1626
  try {
1575
1627
  const { stderr } = await execFileAsync(
1576
- pathResolve(this.popplerPath, "pdfunite"),
1628
+ pathResolve(this.#popplerPath, "pdfunite"),
1577
1629
  ["-v"]
1578
1630
  );
1579
1631
 
@@ -1581,13 +1633,10 @@ class Poppler {
1581
1633
  const versionInfo = popplerVersionRegex.exec(stderr)[1];
1582
1634
 
1583
1635
  const args = parseOptions(acceptedOptions, options, versionInfo);
1584
- files.forEach((element) => {
1585
- args.push(element);
1586
- });
1587
- args.push(outputFile);
1636
+ args.push(...files, outputFile);
1588
1637
 
1589
1638
  const { stdout } = await execFileAsync(
1590
- pathResolve(this.popplerPath, "pdfunite"),
1639
+ pathResolve(this.#popplerPath, "pdfunite"),
1591
1640
  args
1592
1641
  );
1593
1642
  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
  }