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