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.
- package/LICENSE +1 -1
- package/package.json +2 -2
- package/src/index.js +377 -437
package/LICENSE
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-poppler",
|
|
3
|
-
"version": "8.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.
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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 =
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
args.push(file, fileToAttach, outputFile);
|
|
179
|
+
const args = parseOptions(acceptedOptions, options);
|
|
180
|
+
args.push(file, fileToAttach, outputFile);
|
|
180
181
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
args.push(file);
|
|
233
|
+
const args = parseOptions(acceptedOptions, options);
|
|
234
|
+
args.push(file);
|
|
238
235
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
);
|
|
268
|
+
const { stderr } = await execFileAsync(
|
|
269
|
+
pathResolve(this.#popplerPath, "pdffonts"),
|
|
270
|
+
["-v"]
|
|
271
|
+
);
|
|
279
272
|
|
|
280
|
-
|
|
281
|
-
|
|
273
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
274
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
282
275
|
|
|
283
|
-
|
|
276
|
+
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
284
277
|
|
|
285
|
-
|
|
286
|
-
|
|
278
|
+
return new Promise((resolve, reject) => {
|
|
279
|
+
args.push(Buffer.isBuffer(file) ? "-" : file);
|
|
287
280
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
281
|
+
const child = spawn(
|
|
282
|
+
pathResolve(this.#popplerPath, "pdffonts"),
|
|
283
|
+
args
|
|
284
|
+
);
|
|
292
285
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
286
|
+
if (Buffer.isBuffer(file)) {
|
|
287
|
+
child.stdin.write(file);
|
|
288
|
+
child.stdin.end();
|
|
289
|
+
}
|
|
297
290
|
|
|
298
|
-
|
|
299
|
-
|
|
291
|
+
let stdOut = "";
|
|
292
|
+
let stdErr = "";
|
|
300
293
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
294
|
+
child.stdout.on("data", (data) => {
|
|
295
|
+
stdOut += data;
|
|
296
|
+
});
|
|
304
297
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
298
|
+
child.stderr.on("data", (data) => {
|
|
299
|
+
stdErr += data;
|
|
300
|
+
});
|
|
308
301
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
);
|
|
367
|
+
const { stderr } = await execFileAsync(
|
|
368
|
+
pathResolve(this.#popplerPath, "pdfimages"),
|
|
369
|
+
["-v"]
|
|
370
|
+
);
|
|
382
371
|
|
|
383
|
-
|
|
384
|
-
|
|
372
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
373
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
385
374
|
|
|
386
|
-
|
|
375
|
+
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
387
376
|
|
|
388
|
-
|
|
389
|
-
|
|
377
|
+
return new Promise((resolve, reject) => {
|
|
378
|
+
args.push(Buffer.isBuffer(file) ? "-" : file);
|
|
390
379
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
380
|
+
if (outputPrefix) {
|
|
381
|
+
args.push(outputPrefix);
|
|
382
|
+
}
|
|
394
383
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
384
|
+
const child = spawn(
|
|
385
|
+
pathResolve(this.#popplerPath, "pdfimages"),
|
|
386
|
+
args
|
|
387
|
+
);
|
|
399
388
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
389
|
+
if (Buffer.isBuffer(file)) {
|
|
390
|
+
child.stdin.write(file);
|
|
391
|
+
child.stdin.end();
|
|
392
|
+
}
|
|
404
393
|
|
|
405
|
-
|
|
406
|
-
|
|
394
|
+
let stdOut = "";
|
|
395
|
+
let stdErr = "";
|
|
407
396
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
397
|
+
child.stdout.on("data", (data) => {
|
|
398
|
+
stdOut += data;
|
|
399
|
+
});
|
|
411
400
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
401
|
+
child.stderr.on("data", (data) => {
|
|
402
|
+
stdErr += data;
|
|
403
|
+
});
|
|
415
404
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
);
|
|
484
|
+
const { stderr } = await execFileAsync(
|
|
485
|
+
pathResolve(this.#popplerPath, "pdfinfo"),
|
|
486
|
+
["-v"]
|
|
487
|
+
);
|
|
503
488
|
|
|
504
|
-
|
|
505
|
-
|
|
489
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
490
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
506
491
|
|
|
507
|
-
|
|
492
|
+
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
508
493
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
506
|
+
const child = spawn(
|
|
507
|
+
pathResolve(this.#popplerPath, "pdfinfo"),
|
|
508
|
+
args
|
|
509
|
+
);
|
|
528
510
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
511
|
+
if (Buffer.isBuffer(file)) {
|
|
512
|
+
child.stdin.write(file);
|
|
513
|
+
child.stdin.end();
|
|
514
|
+
}
|
|
533
515
|
|
|
534
|
-
|
|
535
|
-
|
|
516
|
+
let stdOut = "";
|
|
517
|
+
let stdErr = "";
|
|
536
518
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
519
|
+
child.stdout.on("data", (data) => {
|
|
520
|
+
stdOut += data;
|
|
521
|
+
});
|
|
540
522
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
523
|
+
child.stderr.on("data", (data) => {
|
|
524
|
+
stdErr += data;
|
|
525
|
+
});
|
|
544
526
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
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
|
-
|
|
576
|
-
resolve(errorMessages[code]);
|
|
577
|
-
} else if (stdErr !== "") {
|
|
578
|
-
reject(new Error(stdErr.trim()));
|
|
549
|
+
resolve(info);
|
|
579
550
|
} else {
|
|
580
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
);
|
|
597
|
+
const { stderr } = await execFileAsync(
|
|
598
|
+
pathResolve(this.#popplerPath, "pdfseparate"),
|
|
599
|
+
["-v"]
|
|
600
|
+
);
|
|
627
601
|
|
|
628
|
-
|
|
629
|
-
|
|
602
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
603
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
630
604
|
|
|
631
|
-
|
|
632
|
-
|
|
605
|
+
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
606
|
+
args.push(file, outputPattern);
|
|
633
607
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
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
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
);
|
|
921
|
+
const { stderr } = await execFileAsync(
|
|
922
|
+
pathResolve(this.#popplerPath, "pdftohtml"),
|
|
923
|
+
["-v"]
|
|
924
|
+
);
|
|
955
925
|
|
|
956
|
-
|
|
957
|
-
|
|
926
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
927
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
958
928
|
|
|
959
|
-
|
|
929
|
+
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
960
930
|
|
|
961
|
-
|
|
962
|
-
|
|
931
|
+
return new Promise((resolve, reject) => {
|
|
932
|
+
args.push(Buffer.isBuffer(file) ? "-" : file);
|
|
963
933
|
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
934
|
+
if (outputFile) {
|
|
935
|
+
args.push(outputFile);
|
|
936
|
+
}
|
|
967
937
|
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
938
|
+
const child = spawn(
|
|
939
|
+
pathResolve(this.#popplerPath, "pdftohtml"),
|
|
940
|
+
args
|
|
941
|
+
);
|
|
972
942
|
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
943
|
+
if (Buffer.isBuffer(file)) {
|
|
944
|
+
child.stdin.write(file);
|
|
945
|
+
child.stdin.end();
|
|
946
|
+
}
|
|
977
947
|
|
|
978
|
-
|
|
979
|
-
|
|
948
|
+
let stdOut = "";
|
|
949
|
+
let stdErr = "";
|
|
980
950
|
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
951
|
+
child.stdout.on("data", (data) => {
|
|
952
|
+
stdOut += data;
|
|
953
|
+
});
|
|
984
954
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
955
|
+
child.stderr.on("data", (data) => {
|
|
956
|
+
stdErr += data;
|
|
957
|
+
});
|
|
988
958
|
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
);
|
|
1116
|
+
const { stderr } = await execFileAsync(
|
|
1117
|
+
pathResolve(this.#popplerPath, "pdftoppm"),
|
|
1118
|
+
["-v"]
|
|
1119
|
+
);
|
|
1157
1120
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1121
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
1122
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
1160
1123
|
|
|
1161
|
-
|
|
1124
|
+
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
1162
1125
|
|
|
1163
|
-
|
|
1164
|
-
|
|
1126
|
+
return new Promise((resolve, reject) => {
|
|
1127
|
+
args.push(Buffer.isBuffer(file) ? "-" : file, outputPath);
|
|
1165
1128
|
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1129
|
+
const child = spawn(
|
|
1130
|
+
pathResolve(this.#popplerPath, "pdftoppm"),
|
|
1131
|
+
args
|
|
1132
|
+
);
|
|
1170
1133
|
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1134
|
+
if (Buffer.isBuffer(file)) {
|
|
1135
|
+
child.stdin.write(file);
|
|
1136
|
+
child.stdin.end();
|
|
1137
|
+
}
|
|
1175
1138
|
|
|
1176
|
-
|
|
1139
|
+
let stdErr = "";
|
|
1177
1140
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1141
|
+
child.stderr.on("data", (data) => {
|
|
1142
|
+
stdErr += data;
|
|
1143
|
+
});
|
|
1181
1144
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
);
|
|
1346
|
+
const { stderr } = await execFileAsync(
|
|
1347
|
+
pathResolve(this.#popplerPath, "pdftops"),
|
|
1348
|
+
["-v"]
|
|
1349
|
+
);
|
|
1391
1350
|
|
|
1392
|
-
|
|
1393
|
-
|
|
1351
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
1352
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
1394
1353
|
|
|
1395
|
-
|
|
1354
|
+
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
1396
1355
|
|
|
1397
|
-
|
|
1398
|
-
|
|
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
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1359
|
+
const child = spawn(
|
|
1360
|
+
pathResolve(this.#popplerPath, "pdftops"),
|
|
1361
|
+
args
|
|
1362
|
+
);
|
|
1407
1363
|
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1364
|
+
if (Buffer.isBuffer(file)) {
|
|
1365
|
+
child.stdin.write(file);
|
|
1366
|
+
child.stdin.end();
|
|
1367
|
+
}
|
|
1412
1368
|
|
|
1413
|
-
|
|
1414
|
-
|
|
1369
|
+
let stdOut = "";
|
|
1370
|
+
let stdErr = "";
|
|
1415
1371
|
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1372
|
+
child.stdout.on("data", (data) => {
|
|
1373
|
+
stdOut += data;
|
|
1374
|
+
});
|
|
1419
1375
|
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1376
|
+
child.stderr.on("data", (data) => {
|
|
1377
|
+
stdErr += data;
|
|
1378
|
+
});
|
|
1423
1379
|
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
);
|
|
1491
|
+
const { stderr } = await execFileAsync(
|
|
1492
|
+
pathResolve(this.#popplerPath, "pdftotext"),
|
|
1493
|
+
["-v"]
|
|
1494
|
+
);
|
|
1543
1495
|
|
|
1544
|
-
|
|
1545
|
-
|
|
1496
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
1497
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
1546
1498
|
|
|
1547
|
-
|
|
1499
|
+
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
1548
1500
|
|
|
1549
|
-
|
|
1550
|
-
|
|
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
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1504
|
+
const child = spawn(
|
|
1505
|
+
pathResolve(this.#popplerPath, "pdftotext"),
|
|
1506
|
+
args
|
|
1507
|
+
);
|
|
1559
1508
|
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1509
|
+
if (Buffer.isBuffer(file)) {
|
|
1510
|
+
child.stdin.write(file);
|
|
1511
|
+
child.stdin.end();
|
|
1512
|
+
}
|
|
1564
1513
|
|
|
1565
|
-
|
|
1566
|
-
|
|
1514
|
+
let stdOut = "";
|
|
1515
|
+
let stdErr = "";
|
|
1567
1516
|
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1517
|
+
child.stdout.on("data", (data) => {
|
|
1518
|
+
stdOut += data;
|
|
1519
|
+
});
|
|
1571
1520
|
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1521
|
+
child.stderr.on("data", (data) => {
|
|
1522
|
+
stdErr += data;
|
|
1523
|
+
});
|
|
1575
1524
|
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
);
|
|
1565
|
+
const { stderr } = await execFileAsync(
|
|
1566
|
+
pathResolve(this.#popplerPath, "pdfunite"),
|
|
1567
|
+
["-v"]
|
|
1568
|
+
);
|
|
1626
1569
|
|
|
1627
|
-
|
|
1628
|
-
|
|
1570
|
+
// @ts-ignore: parseOptions checks if falsy
|
|
1571
|
+
const versionInfo = popplerVersionRegex.exec(stderr)[1];
|
|
1629
1572
|
|
|
1630
|
-
|
|
1631
|
-
|
|
1573
|
+
const args = parseOptions(acceptedOptions, options, versionInfo);
|
|
1574
|
+
args.push(...files, outputFile);
|
|
1632
1575
|
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
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
|
|