node-poppler 7.2.3 → 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.
Files changed (3) hide show
  1. package/README.md +7 -5
  2. package/package.json +2 -3
  3. package/src/index.js +45 -44
package/README.md CHANGED
@@ -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, you will need to download the `poppler-data` and `poppler-utils` binaries separately.
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, you can download the latest versions with [Homebrew](https://brew.sh/):
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
- ## Example usage
42
+ ## API
43
+
44
+ API documentation can be found [here](https://github.com/Fdawgs/node-poppler/blob/main/API.md).
43
45
 
44
- Please refer to the [JSDoc comments in the source code](./src/index.js) or the [generated type definitions](https://www.npmjs.com/package/node-poppler?activeTab=code) for information on the available options.
46
+ ## Example usage
45
47
 
46
48
  ### poppler.pdfToCairo
47
49
 
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-poppler",
3
- "version": "7.2.3",
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 { joinSafe, normalizeTrim } = require("upath");
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 {object} options - Object containing options to pass to binary.
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).forEach((key) => {
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 (acceptedOptions[key].type === typeof options[key]) {
47
+ if (acceptedOption.type === typeof option) {
45
48
  // Skip boolean options if false
46
- if (acceptedOptions[key].type === "boolean" && !options[key]) {
47
- return;
48
- }
49
-
50
- // Arg will be empty for some non-standard options
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
- if (typeof options[key] !== "boolean") {
56
- args.push(options[key]);
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
- acceptedOptions[key].type
62
- } but received ${typeof options[key]}`
62
+ acceptedOption.type
63
+ } but received ${typeof option}`
63
64
  );
64
65
  }
65
66
 
66
67
  if (
67
- acceptedOptions[key].minVersion &&
68
+ acceptedOption.minVersion &&
68
69
  version &&
69
70
  // @ts-ignore: type checking is done above
70
- lt(version, acceptedOptions[key].minVersion, { loose: true })
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${acceptedOptions[key].minVersion}, but received v${version}`
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 = joinSafe(
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 = normalizeTrim(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
- joinSafe(this.popplerPath, "pdfattach"),
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
- joinSafe(this.popplerPath, "pdfdetach"),
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
- joinSafe(this.popplerPath, "pdffonts"),
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
- joinSafe(this.popplerPath, "pdffonts"),
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
- joinSafe(this.popplerPath, "pdfimages"),
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
- joinSafe(this.popplerPath, "pdfimages"),
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
- joinSafe(this.popplerPath, "pdfinfo"),
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
- joinSafe(this.popplerPath, "pdfinfo"),
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
- joinSafe(this.popplerPath, "pdfseparate"),
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
- joinSafe(this.popplerPath, "pdfseparate"),
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
- joinSafe(this.popplerPath, "pdftocairo"),
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
- joinSafe(this.popplerPath, "pdftocairo"),
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
- joinSafe(this.popplerPath, "pdftohtml"),
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
- joinSafe(this.popplerPath, "pdftohtml"),
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
- joinSafe(this.popplerPath, "pdftoppm"),
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
- joinSafe(this.popplerPath, "pdftoppm"),
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
- joinSafe(this.popplerPath, "pdftops"),
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
- joinSafe(this.popplerPath, "pdftops"),
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
- joinSafe(this.popplerPath, "pdftotext"),
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
- joinSafe(this.popplerPath, "pdftotext"),
1511
+ pathResolve(this.popplerPath, "pdftotext"),
1511
1512
  args
1512
1513
  );
1513
1514
 
@@ -1572,7 +1573,7 @@ class Poppler {
1572
1573
 
1573
1574
  try {
1574
1575
  const { stderr } = await execFileAsync(
1575
- joinSafe(this.popplerPath, "pdfunite"),
1576
+ pathResolve(this.popplerPath, "pdfunite"),
1576
1577
  ["-v"]
1577
1578
  );
1578
1579
 
@@ -1586,7 +1587,7 @@ class Poppler {
1586
1587
  args.push(outputFile);
1587
1588
 
1588
1589
  const { stdout } = await execFileAsync(
1589
- joinSafe(this.popplerPath, "pdfunite"),
1590
+ pathResolve(this.popplerPath, "pdfunite"),
1590
1591
  args
1591
1592
  );
1592
1593
  return Promise.resolve(stdout);