node-poppler 7.1.1 → 7.2.0
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/README.md +2 -15
- package/package.json +1 -1
- package/src/index.js +41 -15
- package/types/index.d.ts +8 -2
package/README.md
CHANGED
|
@@ -40,22 +40,9 @@ For macOS users, you can download the latest versions with [Homebrew](https://br
|
|
|
40
40
|
brew install poppler
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
## Example usage
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
const { Poppler } = require("node-poppler");
|
|
47
|
-
const poppler = new Poppler("/usr/bin");
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## API
|
|
51
|
-
|
|
52
|
-
```js
|
|
53
|
-
const { Poppler } = require("node-poppler");
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
[**API Documentation can be found here**](https://github.com/Fdawgs/node-poppler/blob/main/API.md)
|
|
57
|
-
|
|
58
|
-
## Examples
|
|
45
|
+
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.
|
|
59
46
|
|
|
60
47
|
### poppler.pdfToCairo
|
|
61
48
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const { execFile, spawn } = require("node:child_process");
|
|
3
|
+
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");
|
|
@@ -84,24 +84,50 @@ function parseOptions(acceptedOptions, options, version) {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
class Poppler {
|
|
87
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* @param {string} [binPath] - Path of poppler-utils binaries.
|
|
89
|
+
* If not provided, the constructor will attempt to find the Poppler `pdfinfo` binary
|
|
90
|
+
* in the PATH environment variable and use that as the path for all binaries.
|
|
91
|
+
* For `win32` the binaries are bundled with the package and will be used
|
|
92
|
+
* if a local installation is not found.
|
|
93
|
+
*/
|
|
88
94
|
constructor(binPath) {
|
|
95
|
+
this.popplerPath = "";
|
|
96
|
+
|
|
97
|
+
/* istanbul ignore else: requires specific OS */
|
|
89
98
|
if (binPath) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.popplerPath = joinSafe(
|
|
93
|
-
__dirname,
|
|
94
|
-
"lib",
|
|
95
|
-
"win32",
|
|
96
|
-
"poppler-24.02.0",
|
|
97
|
-
"Library",
|
|
98
|
-
"bin"
|
|
99
|
-
);
|
|
99
|
+
/** @type {string|undefined} */
|
|
100
|
+
this.popplerPath = binPath;
|
|
100
101
|
} else {
|
|
102
|
+
const { platform } = process;
|
|
103
|
+
|
|
104
|
+
const which = spawnSync(platform === "win32" ? "where" : "which", [
|
|
105
|
+
"pdfinfo",
|
|
106
|
+
]).stdout.toString();
|
|
107
|
+
const popplerPath = /(.+)pdfinfo/u.exec(which)?.[1];
|
|
108
|
+
|
|
109
|
+
if (popplerPath) {
|
|
110
|
+
this.popplerPath = popplerPath;
|
|
111
|
+
}
|
|
112
|
+
if (platform === "win32" && !popplerPath) {
|
|
113
|
+
this.popplerPath = joinSafe(
|
|
114
|
+
__dirname,
|
|
115
|
+
"lib",
|
|
116
|
+
"win32",
|
|
117
|
+
"poppler-24.02.0",
|
|
118
|
+
"Library",
|
|
119
|
+
"bin"
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* istanbul ignore next: unable to test due to https://github.com/jestjs/jest/pull/14297 */
|
|
125
|
+
if (!this.popplerPath) {
|
|
101
126
|
throw new Error(
|
|
102
|
-
|
|
127
|
+
`Unable to find ${process.platform} Poppler binaries, please pass the installation directory as a parameter to the Poppler instance.`
|
|
103
128
|
);
|
|
104
129
|
}
|
|
130
|
+
this.popplerPath = normalizeTrim(this.popplerPath);
|
|
105
131
|
}
|
|
106
132
|
|
|
107
133
|
/**
|
|
@@ -1568,5 +1594,5 @@ class Poppler {
|
|
|
1568
1594
|
}
|
|
1569
1595
|
}
|
|
1570
1596
|
|
|
1571
|
-
module.exports.
|
|
1572
|
-
module.exports.
|
|
1597
|
+
module.exports.default = Poppler; // ESM default export
|
|
1598
|
+
module.exports.Poppler = Poppler; // TypeScript and named export
|
package/types/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
export default Poppler;
|
|
2
2
|
export class Poppler {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} [binPath] - Path of poppler-utils binaries.
|
|
5
|
+
* If not provided, the constructor will attempt to find the Poppler `pdfinfo` binary
|
|
6
|
+
* in the PATH environment variable and use that as the path for all binaries.
|
|
7
|
+
* For `win32` the binaries are bundled with the package and will be used
|
|
8
|
+
* if a local installation is not found.
|
|
9
|
+
*/
|
|
4
10
|
constructor(binPath?: string);
|
|
5
|
-
popplerPath: string;
|
|
11
|
+
popplerPath: string | undefined;
|
|
6
12
|
/**
|
|
7
13
|
* @author Frazer Smith
|
|
8
14
|
* @description Embeds files (attachments) into a PDF file.
|