node-poppler 7.1.1 → 7.2.1
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 +5 -18
- package/package.json +4 -4
- package/src/index.js +41 -15
- package/types/index.d.ts +22 -16
package/README.md
CHANGED
|
@@ -30,8 +30,7 @@ For Linux users, you will need to download the `poppler-data` and `poppler-utils
|
|
|
30
30
|
An example of downloading the binaries on a Debian system:
|
|
31
31
|
|
|
32
32
|
```
|
|
33
|
-
sudo apt-get install poppler-data
|
|
34
|
-
sudo apt-get install poppler-utils
|
|
33
|
+
sudo apt-get install poppler-data poppler-utils
|
|
35
34
|
```
|
|
36
35
|
|
|
37
36
|
For macOS users, you can download the latest versions with [Homebrew](https://brew.sh/):
|
|
@@ -40,22 +39,9 @@ For macOS users, you can download the latest versions with [Homebrew](https://br
|
|
|
40
39
|
brew install poppler
|
|
41
40
|
```
|
|
42
41
|
|
|
43
|
-
|
|
42
|
+
## Example usage
|
|
44
43
|
|
|
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
|
|
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.
|
|
59
45
|
|
|
60
46
|
### poppler.pdfToCairo
|
|
61
47
|
|
|
@@ -158,9 +144,10 @@ const options = {
|
|
|
158
144
|
firstPageToConvert: 1,
|
|
159
145
|
lastPageToConvert: 2,
|
|
160
146
|
};
|
|
147
|
+
const outputFile = "test_document.txt";
|
|
161
148
|
|
|
162
149
|
poppler
|
|
163
|
-
.pdfToText(file, options)
|
|
150
|
+
.pdfToText(file, outputFile, options)
|
|
164
151
|
.then((res) => {
|
|
165
152
|
console.log(res);
|
|
166
153
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-poppler",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.1",
|
|
4
4
|
"description": "Asynchronous node.js wrapper for the Poppler PDF rendering library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"async",
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
"url": "https://github.com/Fdawgs/node-poppler/issues"
|
|
45
45
|
},
|
|
46
46
|
"license": "MIT",
|
|
47
|
-
"author": "Frazer Smith <frazer.dev@
|
|
47
|
+
"author": "Frazer Smith <frazer.dev@icloud.com>",
|
|
48
48
|
"funding": "https://github.com/sponsors/Fdawgs",
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": ">=18
|
|
50
|
+
"node": ">=18"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"camelcase": "^6.3.0",
|
|
54
|
-
"semver": "^7.6.
|
|
54
|
+
"semver": "^7.6.3",
|
|
55
55
|
"upath": "^2.0.1"
|
|
56
56
|
}
|
|
57
57
|
}
|
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.
|
|
@@ -299,7 +305,7 @@ export class Poppler {
|
|
|
299
305
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
300
306
|
*/
|
|
301
307
|
pdfToCairo(file: Buffer | string, outputFile?: string, options?: {
|
|
302
|
-
antialias?: (
|
|
308
|
+
antialias?: ("best" | "default" | "fast" | "good" | "gray" | "none" | "subpixel");
|
|
303
309
|
cropBox?: boolean;
|
|
304
310
|
cropHeight?: number;
|
|
305
311
|
cropSize?: number;
|
|
@@ -324,7 +330,7 @@ export class Poppler {
|
|
|
324
330
|
originalPageSizes?: boolean;
|
|
325
331
|
ownerPassword?: string;
|
|
326
332
|
paperHeight?: number;
|
|
327
|
-
paperSize?: (
|
|
333
|
+
paperSize?: ("A3" | "A4" | "legal" | "letter" | "match");
|
|
328
334
|
paperWidth?: number;
|
|
329
335
|
pdfFile?: boolean;
|
|
330
336
|
pngFile?: boolean;
|
|
@@ -342,7 +348,7 @@ export class Poppler {
|
|
|
342
348
|
scalePageToYAxis?: number;
|
|
343
349
|
singleFile?: boolean;
|
|
344
350
|
svgFile?: boolean;
|
|
345
|
-
tiffCompression?: (
|
|
351
|
+
tiffCompression?: ("deflate" | "jpeg" | "lzw" | "none" | "packbits");
|
|
346
352
|
tiffFile?: boolean;
|
|
347
353
|
transparentPageColor?: boolean;
|
|
348
354
|
userPassword?: string;
|
|
@@ -395,7 +401,7 @@ export class Poppler {
|
|
|
395
401
|
firstPageToConvert?: number;
|
|
396
402
|
fontFullName?: boolean;
|
|
397
403
|
ignoreImages?: boolean;
|
|
398
|
-
imageFormat?: (
|
|
404
|
+
imageFormat?: ("JPG" | "PNG");
|
|
399
405
|
lastPageToConvert?: number;
|
|
400
406
|
noDrm?: boolean;
|
|
401
407
|
noFrames?: boolean;
|
|
@@ -487,8 +493,8 @@ export class Poppler {
|
|
|
487
493
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
488
494
|
*/
|
|
489
495
|
pdfToPpm(file: Buffer | string, outputPath: string, options?: {
|
|
490
|
-
antialiasFonts?: (
|
|
491
|
-
antialiasVectors?: (
|
|
496
|
+
antialiasFonts?: ("no" | "yes");
|
|
497
|
+
antialiasVectors?: ("no" | "yes");
|
|
492
498
|
cropBox?: boolean;
|
|
493
499
|
cropHeight?: number;
|
|
494
500
|
cropSize?: number;
|
|
@@ -501,7 +507,7 @@ export class Poppler {
|
|
|
501
507
|
displayProfile?: string;
|
|
502
508
|
evenPagesOnly?: boolean;
|
|
503
509
|
firstPageToConvert?: number;
|
|
504
|
-
freetype?: (
|
|
510
|
+
freetype?: ("no" | "yes");
|
|
505
511
|
forcePageNumber?: boolean;
|
|
506
512
|
grayscaleFile?: boolean;
|
|
507
513
|
hideAnnotations?: boolean;
|
|
@@ -522,8 +528,8 @@ export class Poppler {
|
|
|
522
528
|
scalePageToYAxis?: number;
|
|
523
529
|
separator?: string;
|
|
524
530
|
singleFile?: boolean;
|
|
525
|
-
thinLineMode?: (
|
|
526
|
-
tiffCompression?: (
|
|
531
|
+
thinLineMode?: ("none" | "shape" | "solid");
|
|
532
|
+
tiffCompression?: ("deflate" | "jpeg" | "lzw" | "none" | "packbits");
|
|
527
533
|
tiffFile?: boolean;
|
|
528
534
|
userPassword?: string;
|
|
529
535
|
}): Promise<string>;
|
|
@@ -637,7 +643,7 @@ export class Poppler {
|
|
|
637
643
|
* @returns {Promise<string>} A promise that resolves with a stdout string, or rejects with an `Error` object.
|
|
638
644
|
*/
|
|
639
645
|
pdfToPs(file: Buffer | string, outputFile?: string, options?: {
|
|
640
|
-
antialias?: (
|
|
646
|
+
antialias?: ("no" | "yes");
|
|
641
647
|
binary?: boolean;
|
|
642
648
|
defaultCmykProfile?: string;
|
|
643
649
|
defaultGrayProfile?: string;
|
|
@@ -667,15 +673,15 @@ export class Poppler {
|
|
|
667
673
|
overprint?: boolean;
|
|
668
674
|
ownerPassword?: string;
|
|
669
675
|
paperHeight?: number;
|
|
670
|
-
paperSize?: (
|
|
676
|
+
paperSize?: ("A3" | "A4" | "legal" | "letter" | "match");
|
|
671
677
|
paperWidth?: number;
|
|
672
678
|
passfonts?: boolean;
|
|
673
679
|
preload?: boolean;
|
|
674
680
|
printVersionInfo?: boolean;
|
|
675
|
-
processColorFormat?: (
|
|
681
|
+
processColorFormat?: ("CMYK8" | "MONO8" | "RGB8");
|
|
676
682
|
processColorProfile?: string;
|
|
677
683
|
quiet?: boolean;
|
|
678
|
-
rasterize?: (
|
|
684
|
+
rasterize?: ("always" | "never" | "whenneeded");
|
|
679
685
|
resolutionXYAxis?: number;
|
|
680
686
|
userPassword?: string;
|
|
681
687
|
}): Promise<string>;
|
|
@@ -735,7 +741,7 @@ export class Poppler {
|
|
|
735
741
|
cropWidth?: number;
|
|
736
742
|
cropXAxis?: number;
|
|
737
743
|
cropYAxis?: number;
|
|
738
|
-
eolConvention?: (
|
|
744
|
+
eolConvention?: ("dos" | "mac" | "unix");
|
|
739
745
|
firstPageToConvert?: number;
|
|
740
746
|
fixedWidthLayout?: number;
|
|
741
747
|
generateHtmlMetaFile?: boolean;
|