node-poppler 6.1.1 → 6.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 CHANGED
@@ -2,18 +2,17 @@
2
2
 
3
3
  [![GitHub Release](https://img.shields.io/github/release/Fdawgs/node-poppler.svg)](https://github.com/Fdawgs/node-poppler/releases/latest/)
4
4
  [![npm version](https://img.shields.io/npm/v/node-poppler)](https://npmjs.com/package/node-poppler)
5
- ![Build Status](https://github.com/Fdawgs/node-poppler/workflows/CI/badge.svg?branch=master)
6
- [![Coverage Status](https://coveralls.io/repos/github/Fdawgs/node-poppler/badge.svg?branch=master)](https://coveralls.io/github/Fdawgs/node-poppler?branch=master)
5
+ ![Build Status](https://github.com/Fdawgs/node-poppler/workflows/CI/badge.svg?branch=main)
6
+ [![Coverage Status](https://coveralls.io/repos/github/Fdawgs/node-poppler/badge.svg?branch=main)](https://coveralls.io/github/Fdawgs/node-poppler?branch=main)
7
7
  [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat)](https://github.com/prettier/prettier)
8
8
 
9
9
  > Asynchronous node.js wrapper for the Poppler PDF rendering library
10
10
 
11
- ## Intro
11
+ ## Overview
12
12
 
13
13
  [Poppler](https://poppler.freedesktop.org/) is a PDF rendering library that also includes a collection of utility binaries, which allows for the manipulation and extraction of data from PDF documents such as converting PDF files to HTML, TXT, or PostScript.
14
14
 
15
15
  The `node-poppler` module provides an asynchronous node.js wrapper around said utility binaries for easier use.
16
- It was created out of a need for a PDF-to-HTML conversion module at [Yeovil District Hospital NHS Foundation Trust](https://yeovilhospital.co.uk/) to convert clinical documents.
17
16
 
18
17
  ## Installation
19
18
 
@@ -23,7 +22,7 @@ Install using `npm`:
23
22
  npm i node-poppler
24
23
  ```
25
24
 
26
- ### Linux and macOS/Darwin Support
25
+ ### Linux and macOS/Darwin support
27
26
 
28
27
  Windows binaries are provided with this repository.
29
28
  For Linux users, you will need to download the `poppler-data` and `poppler-utils` binaries separately.
@@ -54,7 +53,7 @@ const poppler = new Poppler("/usr/bin");
54
53
  const { Poppler } = require("node-poppler");
55
54
  ```
56
55
 
57
- [**API Documentation can be found here**](https://github.com/Fdawgs/node-poppler/blob/master/API.md)
56
+ [**API Documentation can be found here**](https://github.com/Fdawgs/node-poppler/blob/main/API.md)
58
57
 
59
58
  ## Examples
60
59
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-poppler",
3
- "version": "6.1.1",
3
+ "version": "6.2.0",
4
4
  "description": "Asynchronous node.js wrapper for the Poppler PDF rendering library",
5
5
  "keywords": [
6
6
  "async",
@@ -33,6 +33,7 @@
33
33
  "unite"
34
34
  ],
35
35
  "main": "src/index.js",
36
+ "types": "types/index.d.ts",
36
37
  "repository": "git+https://github.com/Fdawgs/node-poppler.git",
37
38
  "homepage": "https://github.com/Fdawgs/node-poppler",
38
39
  "bugs": {
package/src/index.js CHANGED
@@ -11,6 +11,7 @@ const errorMessages = {
11
11
  1: "Error opening a PDF file",
12
12
  2: "Error opening an output file",
13
13
  3: "Error related to PDF permissions",
14
+ 4: "Error related to ICC profile",
14
15
  99: "Other error",
15
16
  3221226505: "Internal process error",
16
17
  };
@@ -19,10 +20,12 @@ const errorMessages = {
19
20
  * @author Frazer Smith
20
21
  * @description Check each option provided is valid, of the correct type, and can be used by specified
21
22
  * version of binary.
23
+ * @ignore
22
24
  * @param {object} acceptedOptions - Object containing options that a binary accepts.
23
25
  * @param {object} options - Object containing options to pass to binary.
24
26
  * @param {string=} version - Version of binary.
25
- * @returns {Array|Error} Array of CLI arguments or Error object if invalid arguments provided.
27
+ * @returns {Array<string>} Array of CLI arguments.
28
+ * @throws If invalid arguments provided.
26
29
  */
27
30
  function parseOptions(acceptedOptions, options, version) {
28
31
  const args = [];
@@ -245,7 +248,7 @@ class Poppler {
245
248
  if (stdOut !== "") {
246
249
  resolve(stdOut.trim());
247
250
  } else {
248
- reject(new Error(stdErr.trim()));
251
+ reject(new Error(stdErr ? stdErr.trim() : undefined));
249
252
  }
250
253
  });
251
254
  });
@@ -481,7 +484,7 @@ class Poppler {
481
484
  resolve(stdOut.trim());
482
485
  }
483
486
  } else {
484
- reject(new Error(stdErr.trim()));
487
+ reject(new Error(stdErr ? stdErr.trim() : undefined));
485
488
  }
486
489
  });
487
490
  });
@@ -873,16 +876,15 @@ class Poppler {
873
876
  stdErr += data;
874
877
  });
875
878
 
876
- child.on("close", async (code) => {
879
+ /**
880
+ * pdfToHtml does not return an exit code so check output to see if it was successful.
881
+ * See https://gitlab.freedesktop.org/poppler/poppler/-/blob/master/utils/pdftohtml.1
882
+ */
883
+ child.on("close", async () => {
877
884
  if (stdOut !== "") {
878
885
  resolve(stdOut.trim());
879
- } else if (code === 0) {
880
- resolve(errorMessages[code]);
881
- } else if (stdErr !== "") {
882
- reject(new Error(stdErr.trim()));
883
886
  } else {
884
- /* istanbul ignore next */
885
- reject(new Error(errorMessages[code]));
887
+ reject(new Error(stdErr ? stdErr.trim() : undefined));
886
888
  }
887
889
  });
888
890
  });
@@ -1518,6 +1520,5 @@ class Poppler {
1518
1520
  }
1519
1521
  }
1520
1522
 
1521
- module.exports = {
1522
- Poppler,
1523
- };
1523
+ module.exports.Poppler = Poppler;
1524
+ module.exports.default = Poppler;
@@ -1,3 +1,4 @@
1
+ export default Poppler;
1
2
  export class Poppler {
2
3
  /**
3
4
  * @param {string=} binPath - Path of poppler-utils binaries.