node-poppler 8.0.0 → 8.0.2

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.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/package.json +2 -2
  3. package/src/index.js +377 -437
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019-2025 Frazer Smith
3
+ Copyright (c) 2019-present Frazer Smith
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-poppler",
3
- "version": "8.0.0",
3
+ "version": "8.0.2",
4
4
  "description": "Asynchronous Node.js wrapper for the Poppler PDF rendering library",
5
5
  "keywords": [
6
6
  "async",
@@ -51,6 +51,6 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "camelcase": "^6.3.0",
54
- "semver": "^7.6.3"
54
+ "semver": "^7.7.2"
55
55
  }
56
56
  }
package/src/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
 
3
3
  const { execFile, spawn, spawnSync } = require("node:child_process");
4
+ const { normalize, resolve: pathResolve } = require("node:path");
4
5
  const { promisify } = require("node:util");
5
6
  const camelCase = require("camelcase");
6
7
  const { lt } = require("semver");
7
- const { normalize, resolve: pathResolve } = require("node:path");
8
8
 
9
9
  const execFileAsync = promisify(execFile);
10
10
 
@@ -50,15 +50,17 @@ function parseOptions(acceptedOptions, options, version) {
50
50
  const args = [];
51
51
  /** @type {string[]} */
52
52
  const invalidArgs = [];
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];
53
+
54
+ // Imperative loops are faster than functional loops, see https://romgrk.com/posts/optimizing-javascript
55
+ const entries = Object.entries(options);
56
+ const entriesLength = entries.length;
57
+ for (let i = 0; i < entriesLength; i += 1) {
58
+ // Destructuring adds overhead, so use index access
59
+ const key = entries[i][0];
57
60
  if (Object.hasOwn(acceptedOptions, key)) {
58
- const option = options[key];
61
+ const option = entries[i][1];
59
62
  const acceptedOption = acceptedOptions[key];
60
63
 
61
- // eslint-disable-next-line valid-typeof -- `type` is a string
62
64
  if (acceptedOption.type === typeof option) {
63
65
  // Skip boolean options if false
64
66
  if (acceptedOption.type !== "boolean" || option) {
@@ -174,18 +176,14 @@ class Poppler {
174
176
  replace: { arg: "-replace", type: "boolean" },
175
177
  };
176
178
 
177
- try {
178
- const args = parseOptions(acceptedOptions, options);
179
- args.push(file, fileToAttach, outputFile);
179
+ const args = parseOptions(acceptedOptions, options);
180
+ args.push(file, fileToAttach, outputFile);
180
181
 
181
- const { stdout } = await execFileAsync(
182
- pathResolve(this.#popplerPath, "pdfattach"),
183
- args
184
- );
185
- return Promise.resolve(stdout);
186
- } catch (err) {
187
- return Promise.reject(err);
188
- }
182
+ const { stdout } = await execFileAsync(
183
+ pathResolve(this.#popplerPath, "pdfattach"),
184
+ args
185
+ );
186
+ return stdout;
189
187
  }
190
188
 
191
189
  /**
@@ -232,18 +230,14 @@ class Poppler {
232
230
  userPassword: { arg: "-upw", type: "string" },
233
231
  };
234
232
 
235
- try {
236
- const args = parseOptions(acceptedOptions, options);
237
- args.push(file);
233
+ const args = parseOptions(acceptedOptions, options);
234
+ args.push(file);
238
235
 
239
- const { stdout } = await execFileAsync(
240
- pathResolve(this.#popplerPath, "pdfdetach"),
241
- args
242
- );
243
- return Promise.resolve(stdout);
244
- } catch (err) {
245
- return Promise.reject(err);
246
- }
236
+ const { stdout } = await execFileAsync(
237
+ pathResolve(this.#popplerPath, "pdfdetach"),
238
+ args
239
+ );
240
+ return stdout;
247
241
  }
248
242
 
249
243
  /**
@@ -271,65 +265,61 @@ class Poppler {
271
265
  userPassword: { arg: "-upw", type: "string" },
272
266
  };
273
267
 
274
- try {
275
- const { stderr } = await execFileAsync(
276
- pathResolve(this.#popplerPath, "pdffonts"),
277
- ["-v"]
278
- );
268
+ const { stderr } = await execFileAsync(
269
+ pathResolve(this.#popplerPath, "pdffonts"),
270
+ ["-v"]
271
+ );
279
272
 
280
- // @ts-ignore: parseOptions checks if falsy
281
- const versionInfo = popplerVersionRegex.exec(stderr)[1];
273
+ // @ts-ignore: parseOptions checks if falsy
274
+ const versionInfo = popplerVersionRegex.exec(stderr)[1];
282
275
 
283
- const args = parseOptions(acceptedOptions, options, versionInfo);
276
+ const args = parseOptions(acceptedOptions, options, versionInfo);
284
277
 
285
- return new Promise((resolve, reject) => {
286
- args.push(Buffer.isBuffer(file) ? "-" : file);
278
+ return new Promise((resolve, reject) => {
279
+ args.push(Buffer.isBuffer(file) ? "-" : file);
287
280
 
288
- const child = spawn(
289
- pathResolve(this.#popplerPath, "pdffonts"),
290
- args
291
- );
281
+ const child = spawn(
282
+ pathResolve(this.#popplerPath, "pdffonts"),
283
+ args
284
+ );
292
285
 
293
- if (Buffer.isBuffer(file)) {
294
- child.stdin.write(file);
295
- child.stdin.end();
296
- }
286
+ if (Buffer.isBuffer(file)) {
287
+ child.stdin.write(file);
288
+ child.stdin.end();
289
+ }
297
290
 
298
- let stdOut = "";
299
- let stdErr = "";
291
+ let stdOut = "";
292
+ let stdErr = "";
300
293
 
301
- child.stdout.on("data", (data) => {
302
- stdOut += data;
303
- });
294
+ child.stdout.on("data", (data) => {
295
+ stdOut += data;
296
+ });
304
297
 
305
- child.stderr.on("data", (data) => {
306
- stdErr += data;
307
- });
298
+ child.stderr.on("data", (data) => {
299
+ stdErr += data;
300
+ });
308
301
 
309
- child.on("close", (code) => {
310
- /* istanbul ignore else */
311
- if (stdOut !== "") {
312
- resolve(stdOut.trim());
313
- } else if (code === 0) {
314
- resolve(errorMessages[code]);
315
- } else if (stdErr !== "") {
316
- reject(new Error(stdErr.trim()));
317
- } else {
318
- reject(
319
- new Error(
320
- // @ts-ignore: Second operand used if code is not in errorMessages
321
- errorMessages[code] ||
322
- `pdffonts ${args.join(
323
- " "
324
- )} exited with code ${code}`
325
- )
326
- );
327
- }
328
- });
302
+ child.on("close", (code) => {
303
+ /* istanbul ignore else */
304
+ if (stdOut !== "") {
305
+ resolve(stdOut.trim());
306
+ } else if (code === 0) {
307
+ resolve(errorMessages[code]);
308
+ } else if (stdErr !== "") {
309
+ reject(new Error(stdErr.trim()));
310
+ } else {
311
+ reject(
312
+ new Error(
313
+ // @ts-ignore: Second operand used if code is not in errorMessages
314
+ errorMessages[code] ||
315
+ `pdffonts ${args.join(
316
+ " "
317
+ )} exited with code ${code}`
318
+ )
319
+ );
320
+ }
329
321
  });
330
- } catch (err) {
331
- return Promise.reject(err);
332
- }
322
+ });
333
323
  }
334
324
 
335
325
  /**
@@ -374,69 +364,65 @@ class Poppler {
374
364
  userPassword: { arg: "-upw", type: "string" },
375
365
  };
376
366
 
377
- try {
378
- const { stderr } = await execFileAsync(
379
- pathResolve(this.#popplerPath, "pdfimages"),
380
- ["-v"]
381
- );
367
+ const { stderr } = await execFileAsync(
368
+ pathResolve(this.#popplerPath, "pdfimages"),
369
+ ["-v"]
370
+ );
382
371
 
383
- // @ts-ignore: parseOptions checks if falsy
384
- const versionInfo = popplerVersionRegex.exec(stderr)[1];
372
+ // @ts-ignore: parseOptions checks if falsy
373
+ const versionInfo = popplerVersionRegex.exec(stderr)[1];
385
374
 
386
- const args = parseOptions(acceptedOptions, options, versionInfo);
375
+ const args = parseOptions(acceptedOptions, options, versionInfo);
387
376
 
388
- return new Promise((resolve, reject) => {
389
- args.push(Buffer.isBuffer(file) ? "-" : file);
377
+ return new Promise((resolve, reject) => {
378
+ args.push(Buffer.isBuffer(file) ? "-" : file);
390
379
 
391
- if (outputPrefix) {
392
- args.push(outputPrefix);
393
- }
380
+ if (outputPrefix) {
381
+ args.push(outputPrefix);
382
+ }
394
383
 
395
- const child = spawn(
396
- pathResolve(this.#popplerPath, "pdfimages"),
397
- args
398
- );
384
+ const child = spawn(
385
+ pathResolve(this.#popplerPath, "pdfimages"),
386
+ args
387
+ );
399
388
 
400
- if (Buffer.isBuffer(file)) {
401
- child.stdin.write(file);
402
- child.stdin.end();
403
- }
389
+ if (Buffer.isBuffer(file)) {
390
+ child.stdin.write(file);
391
+ child.stdin.end();
392
+ }
404
393
 
405
- let stdOut = "";
406
- let stdErr = "";
394
+ let stdOut = "";
395
+ let stdErr = "";
407
396
 
408
- child.stdout.on("data", (data) => {
409
- stdOut += data;
410
- });
397
+ child.stdout.on("data", (data) => {
398
+ stdOut += data;
399
+ });
411
400
 
412
- child.stderr.on("data", (data) => {
413
- stdErr += data;
414
- });
401
+ child.stderr.on("data", (data) => {
402
+ stdErr += data;
403
+ });
415
404
 
416
- child.on("close", (code) => {
417
- /* istanbul ignore else */
418
- if (stdOut !== "") {
419
- resolve(stdOut.trim());
420
- } else if (code === 0) {
421
- resolve(errorMessages[code]);
422
- } else if (stdErr !== "") {
423
- reject(new Error(stdErr.trim()));
424
- } else {
425
- reject(
426
- new Error(
427
- // @ts-ignore: Second operand used if code is not in errorMessages
428
- errorMessages[code] ||
429
- `pdfimages ${args.join(
430
- " "
431
- )} exited with code ${code}`
432
- )
433
- );
434
- }
435
- });
405
+ child.on("close", (code) => {
406
+ /* istanbul ignore else */
407
+ if (stdOut !== "") {
408
+ resolve(stdOut.trim());
409
+ } else if (code === 0) {
410
+ resolve(errorMessages[code]);
411
+ } else if (stdErr !== "") {
412
+ reject(new Error(stdErr.trim()));
413
+ } else {
414
+ reject(
415
+ new Error(
416
+ // @ts-ignore: Second operand used if code is not in errorMessages
417
+ errorMessages[code] ||
418
+ `pdfimages ${args.join(
419
+ " "
420
+ )} exited with code ${code}`
421
+ )
422
+ );
423
+ }
436
424
  });
437
- } catch (err) {
438
- return Promise.reject(err);
439
- }
425
+ });
440
426
  }
441
427
 
442
428
  /**
@@ -495,103 +481,92 @@ class Poppler {
495
481
  userPassword: { arg: "-upw", type: "string" },
496
482
  };
497
483
 
498
- try {
499
- const { stderr } = await execFileAsync(
500
- pathResolve(this.#popplerPath, "pdfinfo"),
501
- ["-v"]
502
- );
484
+ const { stderr } = await execFileAsync(
485
+ pathResolve(this.#popplerPath, "pdfinfo"),
486
+ ["-v"]
487
+ );
503
488
 
504
- // @ts-ignore: parseOptions checks if falsy
505
- const versionInfo = popplerVersionRegex.exec(stderr)[1];
489
+ // @ts-ignore: parseOptions checks if falsy
490
+ const versionInfo = popplerVersionRegex.exec(stderr)[1];
506
491
 
507
- const args = parseOptions(acceptedOptions, options, versionInfo);
492
+ const args = parseOptions(acceptedOptions, options, versionInfo);
508
493
 
509
- /**
510
- * Poppler does not set the "File size" metadata value if passed
511
- * a Buffer via stdin, so need to retrieve it from the Buffer.
512
- */
513
- /** @type {number} */
514
- let fileSize;
494
+ // Fetch file size if stdin input is a Buffer, as Poppler omits it
495
+ /** @type {number} */
496
+ let fileSize;
515
497
 
516
- return new Promise((resolve, reject) => {
517
- if (Buffer.isBuffer(file)) {
518
- args.push("-");
519
- fileSize = file.length;
520
- } else {
521
- args.push(file);
522
- }
498
+ return new Promise((resolve, reject) => {
499
+ if (Buffer.isBuffer(file)) {
500
+ args.push("-");
501
+ fileSize = file.length;
502
+ } else {
503
+ args.push(file);
504
+ }
523
505
 
524
- const child = spawn(
525
- pathResolve(this.#popplerPath, "pdfinfo"),
526
- args
527
- );
506
+ const child = spawn(
507
+ pathResolve(this.#popplerPath, "pdfinfo"),
508
+ args
509
+ );
528
510
 
529
- if (Buffer.isBuffer(file)) {
530
- child.stdin.write(file);
531
- child.stdin.end();
532
- }
511
+ if (Buffer.isBuffer(file)) {
512
+ child.stdin.write(file);
513
+ child.stdin.end();
514
+ }
533
515
 
534
- let stdOut = "";
535
- let stdErr = "";
516
+ let stdOut = "";
517
+ let stdErr = "";
536
518
 
537
- child.stdout.on("data", (data) => {
538
- stdOut += data;
539
- });
519
+ child.stdout.on("data", (data) => {
520
+ stdOut += data;
521
+ });
540
522
 
541
- child.stderr.on("data", (data) => {
542
- stdErr += data;
543
- });
523
+ child.stderr.on("data", (data) => {
524
+ stdErr += data;
525
+ });
544
526
 
545
- child.on("close", (code) => {
546
- /* istanbul ignore else */
547
- if (stdOut !== "") {
548
- if (fileSize) {
549
- stdOut = stdOut.replace(
550
- pdfInfoFileSizesRegex,
551
- `$1${fileSize}$2bytes`
552
- );
553
- }
527
+ child.on("close", (code) => {
528
+ /* istanbul ignore else */
529
+ if (stdOut !== "") {
530
+ if (fileSize) {
531
+ stdOut = stdOut.replace(
532
+ pdfInfoFileSizesRegex,
533
+ `$1${fileSize}$2bytes`
534
+ );
535
+ }
554
536
 
555
- /**
556
- * Convert output to JSON.
557
- * @see {@link https://github.com/Fdawgs/node-poppler/issues/248#issuecomment-845948080 | Node-Poppler Issue #248}
558
- */
559
- if (options.printAsJson === true) {
560
- const info = {};
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];
565
- const lines = line.split(": ");
566
- if (lines.length > 1) {
567
- // @ts-ignore: creating dynamic object keys
568
- info[camelCase(lines[0])] = lines[1].trim();
569
- }
537
+ if (options.printAsJson === true) {
538
+ const info = {};
539
+ const stdOutLines = stdOut.split("\n");
540
+ const stdOutLinesLength = stdOutLines.length;
541
+ for (let i = 0; i < stdOutLinesLength; i += 1) {
542
+ const line = stdOutLines[i];
543
+ const lines = line.split(": ");
544
+ if (lines.length > 1) {
545
+ // @ts-ignore: creating dynamic object keys
546
+ info[camelCase(lines[0])] = lines[1].trim();
570
547
  }
571
- resolve(info);
572
- } else {
573
- resolve(stdOut.trim());
574
548
  }
575
- } else if (code === 0) {
576
- resolve(errorMessages[code]);
577
- } else if (stdErr !== "") {
578
- reject(new Error(stdErr.trim()));
549
+ resolve(info);
579
550
  } else {
580
- reject(
581
- new Error(
582
- // @ts-ignore: Second operand used if code is not in errorMessages
583
- errorMessages[code] ||
584
- `pdfinfo ${args.join(
585
- " "
586
- )} exited with code ${code}`
587
- )
588
- );
551
+ resolve(stdOut.trim());
589
552
  }
590
- });
553
+ } else if (code === 0) {
554
+ resolve(errorMessages[code]);
555
+ } else if (stdErr !== "") {
556
+ reject(new Error(stdErr.trim()));
557
+ } else {
558
+ reject(
559
+ new Error(
560
+ // @ts-ignore: Second operand used if code is not in errorMessages
561
+ errorMessages[code] ||
562
+ `pdfinfo ${args.join(
563
+ " "
564
+ )} exited with code ${code}`
565
+ )
566
+ );
567
+ }
591
568
  });
592
- } catch (err) {
593
- return Promise.reject(err);
594
- }
569
+ });
595
570
  }
596
571
 
597
572
  /**
@@ -619,26 +594,22 @@ class Poppler {
619
594
  printVersionInfo: { arg: "-v", type: "boolean" },
620
595
  };
621
596
 
622
- try {
623
- const { stderr } = await execFileAsync(
624
- pathResolve(this.#popplerPath, "pdfseparate"),
625
- ["-v"]
626
- );
597
+ const { stderr } = await execFileAsync(
598
+ pathResolve(this.#popplerPath, "pdfseparate"),
599
+ ["-v"]
600
+ );
627
601
 
628
- // @ts-ignore: parseOptions checks if falsy
629
- const versionInfo = popplerVersionRegex.exec(stderr)[1];
602
+ // @ts-ignore: parseOptions checks if falsy
603
+ const versionInfo = popplerVersionRegex.exec(stderr)[1];
630
604
 
631
- const args = parseOptions(acceptedOptions, options, versionInfo);
632
- args.push(file, outputPattern);
605
+ const args = parseOptions(acceptedOptions, options, versionInfo);
606
+ args.push(file, outputPattern);
633
607
 
634
- const { stdout } = await execFileAsync(
635
- pathResolve(this.#popplerPath, "pdfseparate"),
636
- args
637
- );
638
- return Promise.resolve(stdout);
639
- } catch (err) {
640
- return Promise.reject(err);
641
- }
608
+ const { stdout } = await execFileAsync(
609
+ pathResolve(this.#popplerPath, "pdfseparate"),
610
+ args
611
+ );
612
+ return stdout;
642
613
  }
643
614
 
644
615
  /**
@@ -947,60 +918,53 @@ class Poppler {
947
918
  zoom: { arg: "-zoom", type: "number" },
948
919
  };
949
920
 
950
- try {
951
- const { stderr } = await execFileAsync(
952
- pathResolve(this.#popplerPath, "pdftohtml"),
953
- ["-v"]
954
- );
921
+ const { stderr } = await execFileAsync(
922
+ pathResolve(this.#popplerPath, "pdftohtml"),
923
+ ["-v"]
924
+ );
955
925
 
956
- // @ts-ignore: parseOptions checks if falsy
957
- const versionInfo = popplerVersionRegex.exec(stderr)[1];
926
+ // @ts-ignore: parseOptions checks if falsy
927
+ const versionInfo = popplerVersionRegex.exec(stderr)[1];
958
928
 
959
- const args = parseOptions(acceptedOptions, options, versionInfo);
929
+ const args = parseOptions(acceptedOptions, options, versionInfo);
960
930
 
961
- return new Promise((resolve, reject) => {
962
- args.push(Buffer.isBuffer(file) ? "-" : file);
931
+ return new Promise((resolve, reject) => {
932
+ args.push(Buffer.isBuffer(file) ? "-" : file);
963
933
 
964
- if (outputFile) {
965
- args.push(outputFile);
966
- }
934
+ if (outputFile) {
935
+ args.push(outputFile);
936
+ }
967
937
 
968
- const child = spawn(
969
- pathResolve(this.#popplerPath, "pdftohtml"),
970
- args
971
- );
938
+ const child = spawn(
939
+ pathResolve(this.#popplerPath, "pdftohtml"),
940
+ args
941
+ );
972
942
 
973
- if (Buffer.isBuffer(file)) {
974
- child.stdin.write(file);
975
- child.stdin.end();
976
- }
943
+ if (Buffer.isBuffer(file)) {
944
+ child.stdin.write(file);
945
+ child.stdin.end();
946
+ }
977
947
 
978
- let stdOut = "";
979
- let stdErr = "";
948
+ let stdOut = "";
949
+ let stdErr = "";
980
950
 
981
- child.stdout.on("data", (data) => {
982
- stdOut += data;
983
- });
951
+ child.stdout.on("data", (data) => {
952
+ stdOut += data;
953
+ });
984
954
 
985
- child.stderr.on("data", (data) => {
986
- stdErr += data;
987
- });
955
+ child.stderr.on("data", (data) => {
956
+ stdErr += data;
957
+ });
988
958
 
989
- /**
990
- * PdfToHtml does not return an exit code so check output to see if it was successful.
991
- * @see {@link https://gitlab.freedesktop.org/poppler/poppler/-/blob/master/utils/pdftohtml.1 | Poppler pdftohtml man}
992
- */
993
- child.on("close", () => {
994
- if (stdOut !== "") {
995
- resolve(stdOut.trim());
996
- } else {
997
- reject(new Error(stdErr ? stdErr.trim() : undefined));
998
- }
999
- });
959
+ // PdfToHtml has no exit code; check output for success
960
+ child.on("close", () => {
961
+ if (stdOut !== "") {
962
+ resolve(stdOut.trim());
963
+ } else {
964
+ reject(new Error(stdErr ? stdErr.trim() : undefined));
965
+ }
1000
966
  });
1001
- } catch (err) {
1002
- return Promise.reject(err);
1003
- }
967
+ });
1004
968
  }
1005
969
 
1006
970
  /**
@@ -1149,58 +1113,54 @@ class Poppler {
1149
1113
  userPassword: { arg: "-upw", type: "string" },
1150
1114
  };
1151
1115
 
1152
- try {
1153
- const { stderr } = await execFileAsync(
1154
- pathResolve(this.#popplerPath, "pdftoppm"),
1155
- ["-v"]
1156
- );
1116
+ const { stderr } = await execFileAsync(
1117
+ pathResolve(this.#popplerPath, "pdftoppm"),
1118
+ ["-v"]
1119
+ );
1157
1120
 
1158
- // @ts-ignore: parseOptions checks if falsy
1159
- const versionInfo = popplerVersionRegex.exec(stderr)[1];
1121
+ // @ts-ignore: parseOptions checks if falsy
1122
+ const versionInfo = popplerVersionRegex.exec(stderr)[1];
1160
1123
 
1161
- const args = parseOptions(acceptedOptions, options, versionInfo);
1124
+ const args = parseOptions(acceptedOptions, options, versionInfo);
1162
1125
 
1163
- return new Promise((resolve, reject) => {
1164
- args.push(Buffer.isBuffer(file) ? "-" : file, outputPath);
1126
+ return new Promise((resolve, reject) => {
1127
+ args.push(Buffer.isBuffer(file) ? "-" : file, outputPath);
1165
1128
 
1166
- const child = spawn(
1167
- pathResolve(this.#popplerPath, "pdftoppm"),
1168
- args
1169
- );
1129
+ const child = spawn(
1130
+ pathResolve(this.#popplerPath, "pdftoppm"),
1131
+ args
1132
+ );
1170
1133
 
1171
- if (Buffer.isBuffer(file)) {
1172
- child.stdin.write(file);
1173
- child.stdin.end();
1174
- }
1134
+ if (Buffer.isBuffer(file)) {
1135
+ child.stdin.write(file);
1136
+ child.stdin.end();
1137
+ }
1175
1138
 
1176
- let stdErr = "";
1139
+ let stdErr = "";
1177
1140
 
1178
- child.stderr.on("data", (data) => {
1179
- stdErr += data;
1180
- });
1141
+ child.stderr.on("data", (data) => {
1142
+ stdErr += data;
1143
+ });
1181
1144
 
1182
- child.on("close", (code) => {
1183
- /* istanbul ignore else */
1184
- if (stdErr !== "") {
1185
- reject(new Error(stdErr.trim()));
1186
- } else if (code === 0) {
1187
- resolve(errorMessages[code]);
1188
- } else {
1189
- reject(
1190
- new Error(
1191
- // @ts-ignore: Second operand used if code is not in errorMessages
1192
- errorMessages[code] ||
1193
- `pdftoppm ${args.join(
1194
- " "
1195
- )} exited with code ${code}`
1196
- )
1197
- );
1198
- }
1199
- });
1145
+ child.on("close", (code) => {
1146
+ /* istanbul ignore else */
1147
+ if (stdErr !== "") {
1148
+ reject(new Error(stdErr.trim()));
1149
+ } else if (code === 0) {
1150
+ resolve(errorMessages[code]);
1151
+ } else {
1152
+ reject(
1153
+ new Error(
1154
+ // @ts-ignore: Second operand used if code is not in errorMessages
1155
+ errorMessages[code] ||
1156
+ `pdftoppm ${args.join(
1157
+ " "
1158
+ )} exited with code ${code}`
1159
+ )
1160
+ );
1161
+ }
1200
1162
  });
1201
- } catch (err) {
1202
- return Promise.reject(err);
1203
- }
1163
+ });
1204
1164
  }
1205
1165
 
1206
1166
  /**
@@ -1383,68 +1343,61 @@ class Poppler {
1383
1343
  userPassword: { arg: "-upw", type: "string" },
1384
1344
  };
1385
1345
 
1386
- try {
1387
- const { stderr } = await execFileAsync(
1388
- pathResolve(this.#popplerPath, "pdftops"),
1389
- ["-v"]
1390
- );
1346
+ const { stderr } = await execFileAsync(
1347
+ pathResolve(this.#popplerPath, "pdftops"),
1348
+ ["-v"]
1349
+ );
1391
1350
 
1392
- // @ts-ignore: parseOptions checks if falsy
1393
- const versionInfo = popplerVersionRegex.exec(stderr)[1];
1351
+ // @ts-ignore: parseOptions checks if falsy
1352
+ const versionInfo = popplerVersionRegex.exec(stderr)[1];
1394
1353
 
1395
- const args = parseOptions(acceptedOptions, options, versionInfo);
1354
+ const args = parseOptions(acceptedOptions, options, versionInfo);
1396
1355
 
1397
- return new Promise((resolve, reject) => {
1398
- args.push(
1399
- Buffer.isBuffer(file) ? "-" : file,
1400
- outputFile || "-"
1401
- );
1356
+ return new Promise((resolve, reject) => {
1357
+ args.push(Buffer.isBuffer(file) ? "-" : file, outputFile || "-");
1402
1358
 
1403
- const child = spawn(
1404
- pathResolve(this.#popplerPath, "pdftops"),
1405
- args
1406
- );
1359
+ const child = spawn(
1360
+ pathResolve(this.#popplerPath, "pdftops"),
1361
+ args
1362
+ );
1407
1363
 
1408
- if (Buffer.isBuffer(file)) {
1409
- child.stdin.write(file);
1410
- child.stdin.end();
1411
- }
1364
+ if (Buffer.isBuffer(file)) {
1365
+ child.stdin.write(file);
1366
+ child.stdin.end();
1367
+ }
1412
1368
 
1413
- let stdOut = "";
1414
- let stdErr = "";
1369
+ let stdOut = "";
1370
+ let stdErr = "";
1415
1371
 
1416
- child.stdout.on("data", (data) => {
1417
- stdOut += data;
1418
- });
1372
+ child.stdout.on("data", (data) => {
1373
+ stdOut += data;
1374
+ });
1419
1375
 
1420
- child.stderr.on("data", (data) => {
1421
- stdErr += data;
1422
- });
1376
+ child.stderr.on("data", (data) => {
1377
+ stdErr += data;
1378
+ });
1423
1379
 
1424
- child.on("close", (code) => {
1425
- /* istanbul ignore else */
1426
- if (stdOut !== "") {
1427
- resolve(stdOut.trim());
1428
- } else if (code === 0) {
1429
- resolve(errorMessages[code]);
1430
- } else if (stdErr !== "") {
1431
- reject(new Error(stdErr.trim()));
1432
- } else {
1433
- reject(
1434
- new Error(
1435
- // @ts-ignore: Second operand used if code is not in errorMessages
1436
- errorMessages[code] ||
1437
- `pdftops ${args.join(
1438
- " "
1439
- )} exited with code ${code}`
1440
- )
1441
- );
1442
- }
1443
- });
1380
+ child.on("close", (code) => {
1381
+ /* istanbul ignore else */
1382
+ if (stdOut !== "") {
1383
+ resolve(stdOut.trim());
1384
+ } else if (code === 0) {
1385
+ resolve(errorMessages[code]);
1386
+ } else if (stdErr !== "") {
1387
+ reject(new Error(stdErr.trim()));
1388
+ } else {
1389
+ reject(
1390
+ new Error(
1391
+ // @ts-ignore: Second operand used if code is not in errorMessages
1392
+ errorMessages[code] ||
1393
+ `pdftops ${args.join(
1394
+ " "
1395
+ )} exited with code ${code}`
1396
+ )
1397
+ );
1398
+ }
1444
1399
  });
1445
- } catch (err) {
1446
- return Promise.reject(err);
1447
- }
1400
+ });
1448
1401
  }
1449
1402
 
1450
1403
  /**
@@ -1535,70 +1488,61 @@ class Poppler {
1535
1488
  userPassword: { arg: "-upw", type: "string" },
1536
1489
  };
1537
1490
 
1538
- try {
1539
- const { stderr } = await execFileAsync(
1540
- pathResolve(this.#popplerPath, "pdftotext"),
1541
- ["-v"]
1542
- );
1491
+ const { stderr } = await execFileAsync(
1492
+ pathResolve(this.#popplerPath, "pdftotext"),
1493
+ ["-v"]
1494
+ );
1543
1495
 
1544
- // @ts-ignore: parseOptions checks if falsy
1545
- const versionInfo = popplerVersionRegex.exec(stderr)[1];
1496
+ // @ts-ignore: parseOptions checks if falsy
1497
+ const versionInfo = popplerVersionRegex.exec(stderr)[1];
1546
1498
 
1547
- const args = parseOptions(acceptedOptions, options, versionInfo);
1499
+ const args = parseOptions(acceptedOptions, options, versionInfo);
1548
1500
 
1549
- return new Promise((resolve, reject) => {
1550
- args.push(
1551
- Buffer.isBuffer(file) ? "-" : file,
1552
- outputFile || "-"
1553
- );
1501
+ return new Promise((resolve, reject) => {
1502
+ args.push(Buffer.isBuffer(file) ? "-" : file, outputFile || "-");
1554
1503
 
1555
- const child = spawn(
1556
- pathResolve(this.#popplerPath, "pdftotext"),
1557
- args
1558
- );
1504
+ const child = spawn(
1505
+ pathResolve(this.#popplerPath, "pdftotext"),
1506
+ args
1507
+ );
1559
1508
 
1560
- if (Buffer.isBuffer(file)) {
1561
- child.stdin.write(file);
1562
- child.stdin.end();
1563
- }
1509
+ if (Buffer.isBuffer(file)) {
1510
+ child.stdin.write(file);
1511
+ child.stdin.end();
1512
+ }
1564
1513
 
1565
- let stdOut = "";
1566
- let stdErr = "";
1514
+ let stdOut = "";
1515
+ let stdErr = "";
1567
1516
 
1568
- child.stdout.on("data", (data) => {
1569
- stdOut += data;
1570
- });
1517
+ child.stdout.on("data", (data) => {
1518
+ stdOut += data;
1519
+ });
1571
1520
 
1572
- child.stderr.on("data", (data) => {
1573
- stdErr += data;
1574
- });
1521
+ child.stderr.on("data", (data) => {
1522
+ stdErr += data;
1523
+ });
1575
1524
 
1576
- child.on("close", (code) => {
1577
- /* istanbul ignore else */
1578
- if (stdOut !== "") {
1579
- resolve(
1580
- options.maintainLayout ? stdOut : stdOut.trim()
1581
- );
1582
- } else if (code === 0) {
1583
- resolve(errorMessages[code]);
1584
- } else if (stdErr !== "") {
1585
- reject(new Error(stdErr.trim()));
1586
- } else {
1587
- reject(
1588
- new Error(
1589
- // @ts-ignore: Second operand used if code is not in errorMessages
1590
- errorMessages[code] ||
1591
- `pdftotext ${args.join(
1592
- " "
1593
- )} exited with code ${code}`
1594
- )
1595
- );
1596
- }
1597
- });
1525
+ child.on("close", (code) => {
1526
+ /* istanbul ignore else */
1527
+ if (stdOut !== "") {
1528
+ resolve(options.maintainLayout ? stdOut : stdOut.trim());
1529
+ } else if (code === 0) {
1530
+ resolve(errorMessages[code]);
1531
+ } else if (stdErr !== "") {
1532
+ reject(new Error(stdErr.trim()));
1533
+ } else {
1534
+ reject(
1535
+ new Error(
1536
+ // @ts-ignore: Second operand used if code is not in errorMessages
1537
+ errorMessages[code] ||
1538
+ `pdftotext ${args.join(
1539
+ " "
1540
+ )} exited with code ${code}`
1541
+ )
1542
+ );
1543
+ }
1598
1544
  });
1599
- } catch (err) {
1600
- return Promise.reject(err);
1601
- }
1545
+ });
1602
1546
  }
1603
1547
 
1604
1548
  /**
@@ -1618,26 +1562,22 @@ class Poppler {
1618
1562
  printVersionInfo: { arg: "-v", type: "boolean" },
1619
1563
  };
1620
1564
 
1621
- try {
1622
- const { stderr } = await execFileAsync(
1623
- pathResolve(this.#popplerPath, "pdfunite"),
1624
- ["-v"]
1625
- );
1565
+ const { stderr } = await execFileAsync(
1566
+ pathResolve(this.#popplerPath, "pdfunite"),
1567
+ ["-v"]
1568
+ );
1626
1569
 
1627
- // @ts-ignore: parseOptions checks if falsy
1628
- const versionInfo = popplerVersionRegex.exec(stderr)[1];
1570
+ // @ts-ignore: parseOptions checks if falsy
1571
+ const versionInfo = popplerVersionRegex.exec(stderr)[1];
1629
1572
 
1630
- const args = parseOptions(acceptedOptions, options, versionInfo);
1631
- args.push(...files, outputFile);
1573
+ const args = parseOptions(acceptedOptions, options, versionInfo);
1574
+ args.push(...files, outputFile);
1632
1575
 
1633
- const { stdout } = await execFileAsync(
1634
- pathResolve(this.#popplerPath, "pdfunite"),
1635
- args
1636
- );
1637
- return Promise.resolve(stdout);
1638
- } catch (err) {
1639
- return Promise.reject(err);
1640
- }
1576
+ const { stdout } = await execFileAsync(
1577
+ pathResolve(this.#popplerPath, "pdfunite"),
1578
+ args
1579
+ );
1580
+ return stdout;
1641
1581
  }
1642
1582
  }
1643
1583