node-poppler 7.2.2 → 7.2.4
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 +2 -2
- package/README.md +15 -13
- package/package.json +2 -3
- package/src/index.js +48 -45
- package/types/index.d.ts +1 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2019-
|
|
3
|
+
Copyright (c) 2019-2025 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
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/Fdawgs/node-poppler/releases/latest/)
|
|
4
4
|
[](https://npmjs.com/package/node-poppler)
|
|
5
|
-
[](https://github.com/Fdawgs/node-poppler/actions/workflows/ci.yml)
|
|
6
6
|
[](https://coveralls.io/github/Fdawgs/node-poppler?branch=main)
|
|
7
7
|
[](https://github.com/prettier/prettier)
|
|
8
8
|
|
|
@@ -25,7 +25,7 @@ npm i node-poppler
|
|
|
25
25
|
### Linux and macOS/Darwin support
|
|
26
26
|
|
|
27
27
|
Windows binaries are provided with this repository.
|
|
28
|
-
For Linux users,
|
|
28
|
+
For Linux and Mac users, the `poppler-data` and `poppler-utils` binaries binary will need to be installed separately.
|
|
29
29
|
|
|
30
30
|
An example of downloading the binaries on a Debian system:
|
|
31
31
|
|
|
@@ -33,15 +33,17 @@ An example of downloading the binaries on a Debian system:
|
|
|
33
33
|
sudo apt-get install poppler-data poppler-utils
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
For macOS users,
|
|
36
|
+
For macOS users, the binaries can be installed with [Homebrew](https://brew.sh/):
|
|
37
37
|
|
|
38
38
|
```
|
|
39
39
|
brew install poppler
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
##
|
|
42
|
+
## API
|
|
43
|
+
|
|
44
|
+
API documentation can be found [here](https://github.com/Fdawgs/node-poppler/blob/main/API.md).
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
## Example usage
|
|
45
47
|
|
|
46
48
|
### poppler.pdfToCairo
|
|
47
49
|
|
|
@@ -63,7 +65,7 @@ const res = await poppler.pdfToCairo(file, outputFile, options);
|
|
|
63
65
|
console.log(res);
|
|
64
66
|
```
|
|
65
67
|
|
|
66
|
-
Example of an `async` `await` call to `poppler.pdfToCairo()`, to convert only the first of a PDF file to a new
|
|
68
|
+
Example of an `async` `await` call to `poppler.pdfToCairo()`, to convert only the first page of a PDF file to a new
|
|
67
69
|
PDF file using stdout:
|
|
68
70
|
|
|
69
71
|
```js
|
|
@@ -79,7 +81,7 @@ const options = {
|
|
|
79
81
|
|
|
80
82
|
const res = await poppler.pdfToCairo(file, undefined, options);
|
|
81
83
|
// pdfToCairo writes to stdout using binary encoding if pdfFile or singleFile options are used
|
|
82
|
-
await writeFile("new_file.pdf", res, { encoding: "binary" });
|
|
84
|
+
await writeFile("new_file.pdf", res, { encoding: "binary", flush: true });
|
|
83
85
|
```
|
|
84
86
|
|
|
85
87
|
### poppler.pdfToHtml
|
|
@@ -166,12 +168,12 @@ Please adhere to this project's [Code of Conduct](https://github.com/Fdawgs/.git
|
|
|
166
168
|
|
|
167
169
|
## Acknowledgements
|
|
168
170
|
|
|
169
|
-
-
|
|
170
|
-
-
|
|
171
|
-
-
|
|
172
|
-
-
|
|
173
|
-
-
|
|
174
|
-
-
|
|
171
|
+
- [**Albert Astals Cid**](https://github.com/albert-astals-cid-kdab) - [Poppler](https://poppler.freedesktop.org/) developer
|
|
172
|
+
- [**Filipe Fernandes**](https://github.com/ocefpaf/) - [poppler-feedstock](https://github.com/conda-forge/poppler-feedstock) maintainer
|
|
173
|
+
- [**Peter Williams**](https://github.com/pkgw/) - [poppler-feedstock](https://github.com/conda-forge/poppler-feedstock) maintainer
|
|
174
|
+
- [**Owen Schwartz**](https://github.com/oschwartz10612) - [poppler-windows](https://github.com/oschwartz10612/poppler-windows) developer
|
|
175
|
+
- [**Uwe Korn**](https://github.com/xhochy/) - [poppler-feedstock](https://github.com/conda-forge/poppler-feedstock) maintainer
|
|
176
|
+
- [**Xylar Asay-Davis**](https://github.com/xylar/) - [poppler-feedstock](https://github.com/conda-forge/poppler-feedstock) maintainer
|
|
175
177
|
|
|
176
178
|
## License
|
|
177
179
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-poppler",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.4",
|
|
4
4
|
"description": "Asynchronous node.js wrapper for the Poppler PDF rendering library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"async",
|
|
@@ -51,7 +51,6 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"camelcase": "^6.3.0",
|
|
54
|
-
"semver": "^7.6.3"
|
|
55
|
-
"upath": "^2.0.1"
|
|
54
|
+
"semver": "^7.6.3"
|
|
56
55
|
}
|
|
57
56
|
}
|
package/src/index.js
CHANGED
|
@@ -4,7 +4,7 @@ const { execFile, spawn, spawnSync } = require("node:child_process");
|
|
|
4
4
|
const { promisify } = require("node:util");
|
|
5
5
|
const camelCase = require("camelcase");
|
|
6
6
|
const { lt } = require("semver");
|
|
7
|
-
const {
|
|
7
|
+
const { normalize, resolve: pathResolve } = require("node:path");
|
|
8
8
|
|
|
9
9
|
const execFileAsync = promisify(execFile);
|
|
10
10
|
|
|
@@ -28,7 +28,7 @@ const pdfInfoFileSizesRegex = /(File\s+size:\s+)0(\s+)bytes/u;
|
|
|
28
28
|
* version of binary.
|
|
29
29
|
* @ignore
|
|
30
30
|
* @param {object} acceptedOptions - Object containing accepted options.
|
|
31
|
-
* @param {
|
|
31
|
+
* @param {Record<string, any>} options - Object containing options to pass to binary.
|
|
32
32
|
* @param {string} [version] - Version of binary.
|
|
33
33
|
* @returns {string[]} Array of CLI arguments.
|
|
34
34
|
* @throws If invalid arguments provided.
|
|
@@ -38,45 +38,46 @@ function parseOptions(acceptedOptions, options, version) {
|
|
|
38
38
|
const args = [];
|
|
39
39
|
/** @type {string[]} */
|
|
40
40
|
const invalidArgs = [];
|
|
41
|
-
Object.keys(options)
|
|
41
|
+
for (const key of Object.keys(options)) {
|
|
42
42
|
if (Object.hasOwn(acceptedOptions, key)) {
|
|
43
|
+
const option = options[key];
|
|
44
|
+
const acceptedOption = acceptedOptions[key];
|
|
45
|
+
|
|
43
46
|
// eslint-disable-next-line valid-typeof -- `type` is a string
|
|
44
|
-
if (
|
|
47
|
+
if (acceptedOption.type === typeof option) {
|
|
45
48
|
// Skip boolean options if false
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (acceptedOptions[key].arg !== "") {
|
|
52
|
-
args.push(acceptedOptions[key].arg);
|
|
53
|
-
}
|
|
49
|
+
if (acceptedOption.type !== "boolean" || option) {
|
|
50
|
+
// Arg will be empty for some non-standard options
|
|
51
|
+
if (acceptedOption.arg !== "") {
|
|
52
|
+
args.push(acceptedOption.arg);
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
if (typeof option !== "boolean") {
|
|
56
|
+
args.push(option);
|
|
57
|
+
}
|
|
57
58
|
}
|
|
58
59
|
} else {
|
|
59
60
|
invalidArgs.push(
|
|
60
61
|
`Invalid value type provided for option '${key}', expected ${
|
|
61
|
-
|
|
62
|
-
} but received ${typeof
|
|
62
|
+
acceptedOption.type
|
|
63
|
+
} but received ${typeof option}`
|
|
63
64
|
);
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
if (
|
|
67
|
-
|
|
68
|
+
acceptedOption.minVersion &&
|
|
68
69
|
version &&
|
|
69
70
|
// @ts-ignore: type checking is done above
|
|
70
|
-
lt(version,
|
|
71
|
+
lt(version, acceptedOption.minVersion, { loose: true })
|
|
71
72
|
) {
|
|
72
73
|
invalidArgs.push(
|
|
73
|
-
`Invalid option provided for the current version of the binary used. '${key}' was introduced in v${
|
|
74
|
+
`Invalid option provided for the current version of the binary used. '${key}' was introduced in v${acceptedOption.minVersion}, but received v${version}`
|
|
74
75
|
);
|
|
75
76
|
}
|
|
76
77
|
} else {
|
|
77
78
|
invalidArgs.push(`Invalid option provided '${key}'`);
|
|
78
79
|
}
|
|
79
|
-
}
|
|
80
|
+
}
|
|
80
81
|
if (invalidArgs.length === 0) {
|
|
81
82
|
return args;
|
|
82
83
|
}
|
|
@@ -110,7 +111,7 @@ class Poppler {
|
|
|
110
111
|
this.popplerPath = popplerPath;
|
|
111
112
|
}
|
|
112
113
|
if (platform === "win32" && !popplerPath) {
|
|
113
|
-
this.popplerPath =
|
|
114
|
+
this.popplerPath = pathResolve(
|
|
114
115
|
__dirname,
|
|
115
116
|
"lib",
|
|
116
117
|
"win32",
|
|
@@ -127,7 +128,7 @@ class Poppler {
|
|
|
127
128
|
`Unable to find ${process.platform} Poppler binaries, please pass the installation directory as a parameter to the Poppler instance.`
|
|
128
129
|
);
|
|
129
130
|
}
|
|
130
|
-
this.popplerPath =
|
|
131
|
+
this.popplerPath = normalize(this.popplerPath);
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
/**
|
|
@@ -152,7 +153,7 @@ class Poppler {
|
|
|
152
153
|
args.push(file, fileToAttach, outputFile);
|
|
153
154
|
|
|
154
155
|
const { stdout } = await execFileAsync(
|
|
155
|
-
|
|
156
|
+
pathResolve(this.popplerPath, "pdfattach"),
|
|
156
157
|
args
|
|
157
158
|
);
|
|
158
159
|
return Promise.resolve(stdout);
|
|
@@ -209,7 +210,7 @@ class Poppler {
|
|
|
209
210
|
args.push(file);
|
|
210
211
|
|
|
211
212
|
const { stdout } = await execFileAsync(
|
|
212
|
-
|
|
213
|
+
pathResolve(this.popplerPath, "pdfdetach"),
|
|
213
214
|
args
|
|
214
215
|
);
|
|
215
216
|
return Promise.resolve(stdout);
|
|
@@ -244,7 +245,7 @@ class Poppler {
|
|
|
244
245
|
|
|
245
246
|
try {
|
|
246
247
|
const { stderr } = await execFileAsync(
|
|
247
|
-
|
|
248
|
+
pathResolve(this.popplerPath, "pdffonts"),
|
|
248
249
|
["-v"]
|
|
249
250
|
);
|
|
250
251
|
|
|
@@ -257,7 +258,7 @@ class Poppler {
|
|
|
257
258
|
args.push(Buffer.isBuffer(file) ? "-" : file);
|
|
258
259
|
|
|
259
260
|
const child = spawn(
|
|
260
|
-
|
|
261
|
+
pathResolve(this.popplerPath, "pdffonts"),
|
|
261
262
|
args
|
|
262
263
|
);
|
|
263
264
|
|
|
@@ -345,7 +346,7 @@ class Poppler {
|
|
|
345
346
|
|
|
346
347
|
try {
|
|
347
348
|
const { stderr } = await execFileAsync(
|
|
348
|
-
|
|
349
|
+
pathResolve(this.popplerPath, "pdfimages"),
|
|
349
350
|
["-v"]
|
|
350
351
|
);
|
|
351
352
|
|
|
@@ -362,7 +363,7 @@ class Poppler {
|
|
|
362
363
|
}
|
|
363
364
|
|
|
364
365
|
const child = spawn(
|
|
365
|
-
|
|
366
|
+
pathResolve(this.popplerPath, "pdfimages"),
|
|
366
367
|
args
|
|
367
368
|
);
|
|
368
369
|
|
|
@@ -464,7 +465,7 @@ class Poppler {
|
|
|
464
465
|
|
|
465
466
|
try {
|
|
466
467
|
const { stderr } = await execFileAsync(
|
|
467
|
-
|
|
468
|
+
pathResolve(this.popplerPath, "pdfinfo"),
|
|
468
469
|
["-v"]
|
|
469
470
|
);
|
|
470
471
|
|
|
@@ -489,7 +490,7 @@ class Poppler {
|
|
|
489
490
|
}
|
|
490
491
|
|
|
491
492
|
const child = spawn(
|
|
492
|
-
|
|
493
|
+
pathResolve(this.popplerPath, "pdfinfo"),
|
|
493
494
|
args
|
|
494
495
|
);
|
|
495
496
|
|
|
@@ -583,7 +584,7 @@ class Poppler {
|
|
|
583
584
|
|
|
584
585
|
try {
|
|
585
586
|
const { stderr } = await execFileAsync(
|
|
586
|
-
|
|
587
|
+
pathResolve(this.popplerPath, "pdfseparate"),
|
|
587
588
|
["-v"]
|
|
588
589
|
);
|
|
589
590
|
|
|
@@ -594,7 +595,7 @@ class Poppler {
|
|
|
594
595
|
args.push(file, outputPattern);
|
|
595
596
|
|
|
596
597
|
const { stdout } = await execFileAsync(
|
|
597
|
-
|
|
598
|
+
pathResolve(this.popplerPath, "pdfseparate"),
|
|
598
599
|
args
|
|
599
600
|
);
|
|
600
601
|
return Promise.resolve(stdout);
|
|
@@ -767,7 +768,7 @@ class Poppler {
|
|
|
767
768
|
|
|
768
769
|
try {
|
|
769
770
|
const { stderr } = await execFileAsync(
|
|
770
|
-
|
|
771
|
+
pathResolve(this.popplerPath, "pdftocairo"),
|
|
771
772
|
["-v"]
|
|
772
773
|
);
|
|
773
774
|
|
|
@@ -783,7 +784,7 @@ class Poppler {
|
|
|
783
784
|
);
|
|
784
785
|
|
|
785
786
|
const child = spawn(
|
|
786
|
-
|
|
787
|
+
pathResolve(this.popplerPath, "pdftocairo"),
|
|
787
788
|
args
|
|
788
789
|
);
|
|
789
790
|
|
|
@@ -908,7 +909,7 @@ class Poppler {
|
|
|
908
909
|
|
|
909
910
|
try {
|
|
910
911
|
const { stderr } = await execFileAsync(
|
|
911
|
-
|
|
912
|
+
pathResolve(this.popplerPath, "pdftohtml"),
|
|
912
913
|
["-v"]
|
|
913
914
|
);
|
|
914
915
|
|
|
@@ -925,7 +926,7 @@ class Poppler {
|
|
|
925
926
|
}
|
|
926
927
|
|
|
927
928
|
const child = spawn(
|
|
928
|
-
|
|
929
|
+
pathResolve(this.popplerPath, "pdftohtml"),
|
|
929
930
|
args
|
|
930
931
|
);
|
|
931
932
|
|
|
@@ -1109,7 +1110,7 @@ class Poppler {
|
|
|
1109
1110
|
|
|
1110
1111
|
try {
|
|
1111
1112
|
const { stderr } = await execFileAsync(
|
|
1112
|
-
|
|
1113
|
+
pathResolve(this.popplerPath, "pdftoppm"),
|
|
1113
1114
|
["-v"]
|
|
1114
1115
|
);
|
|
1115
1116
|
|
|
@@ -1122,7 +1123,7 @@ class Poppler {
|
|
|
1122
1123
|
args.push(Buffer.isBuffer(file) ? "-" : file, outputPath);
|
|
1123
1124
|
|
|
1124
1125
|
const child = spawn(
|
|
1125
|
-
|
|
1126
|
+
pathResolve(this.popplerPath, "pdftoppm"),
|
|
1126
1127
|
args
|
|
1127
1128
|
);
|
|
1128
1129
|
|
|
@@ -1341,7 +1342,7 @@ class Poppler {
|
|
|
1341
1342
|
|
|
1342
1343
|
try {
|
|
1343
1344
|
const { stderr } = await execFileAsync(
|
|
1344
|
-
|
|
1345
|
+
pathResolve(this.popplerPath, "pdftops"),
|
|
1345
1346
|
["-v"]
|
|
1346
1347
|
);
|
|
1347
1348
|
|
|
@@ -1357,7 +1358,7 @@ class Poppler {
|
|
|
1357
1358
|
);
|
|
1358
1359
|
|
|
1359
1360
|
const child = spawn(
|
|
1360
|
-
|
|
1361
|
+
pathResolve(this.popplerPath, "pdftops"),
|
|
1361
1362
|
args
|
|
1362
1363
|
);
|
|
1363
1364
|
|
|
@@ -1491,7 +1492,7 @@ class Poppler {
|
|
|
1491
1492
|
|
|
1492
1493
|
try {
|
|
1493
1494
|
const { stderr } = await execFileAsync(
|
|
1494
|
-
|
|
1495
|
+
pathResolve(this.popplerPath, "pdftotext"),
|
|
1495
1496
|
["-v"]
|
|
1496
1497
|
);
|
|
1497
1498
|
|
|
@@ -1507,7 +1508,7 @@ class Poppler {
|
|
|
1507
1508
|
);
|
|
1508
1509
|
|
|
1509
1510
|
const child = spawn(
|
|
1510
|
-
|
|
1511
|
+
pathResolve(this.popplerPath, "pdftotext"),
|
|
1511
1512
|
args
|
|
1512
1513
|
);
|
|
1513
1514
|
|
|
@@ -1530,7 +1531,9 @@ class Poppler {
|
|
|
1530
1531
|
child.on("close", (code) => {
|
|
1531
1532
|
/* istanbul ignore else */
|
|
1532
1533
|
if (stdOut !== "") {
|
|
1533
|
-
resolve(
|
|
1534
|
+
resolve(
|
|
1535
|
+
options.maintainLayout ? stdOut : stdOut.trim()
|
|
1536
|
+
);
|
|
1534
1537
|
} else if (code === 0) {
|
|
1535
1538
|
resolve(errorMessages[code]);
|
|
1536
1539
|
} else if (stdErr !== "") {
|
|
@@ -1570,7 +1573,7 @@ class Poppler {
|
|
|
1570
1573
|
|
|
1571
1574
|
try {
|
|
1572
1575
|
const { stderr } = await execFileAsync(
|
|
1573
|
-
|
|
1576
|
+
pathResolve(this.popplerPath, "pdfunite"),
|
|
1574
1577
|
["-v"]
|
|
1575
1578
|
);
|
|
1576
1579
|
|
|
@@ -1584,7 +1587,7 @@ class Poppler {
|
|
|
1584
1587
|
args.push(outputFile);
|
|
1585
1588
|
|
|
1586
1589
|
const { stdout } = await execFileAsync(
|
|
1587
|
-
|
|
1590
|
+
pathResolve(this.popplerPath, "pdfunite"),
|
|
1588
1591
|
args
|
|
1589
1592
|
);
|
|
1590
1593
|
return Promise.resolve(stdout);
|
package/types/index.d.ts
CHANGED