https://github.com/fdawgs/node-poppler
Asynchronous Node.js wrapper for the Poppler PDF rendering library
https://github.com/fdawgs/node-poppler
async attach cairo converter detach html pdf pdf-converter pdf-to-cairo pdf-to-html pdf-to-image pdf-to-ppm pdf-to-ps poppler ppm ps separate text txt unite
Last synced: 4 months ago
JSON representation
Asynchronous Node.js wrapper for the Poppler PDF rendering library
- Host: GitHub
- URL: https://github.com/fdawgs/node-poppler
- Owner: Fdawgs
- License: mit
- Created: 2019-10-12T10:16:47.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-04-01T18:44:33.000Z (about 1 year ago)
- Last Synced: 2025-04-07T04:09:16.114Z (about 1 year ago)
- Topics: async, attach, cairo, converter, detach, html, pdf, pdf-converter, pdf-to-cairo, pdf-to-html, pdf-to-image, pdf-to-ppm, pdf-to-ps, poppler, ppm, ps, separate, text, txt, unite
- Language: JavaScript
- Homepage: https://npmjs.com/package/node-poppler
- Size: 87 MB
- Stars: 211
- Watchers: 2
- Forks: 26
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# node-poppler
[](https://github.com/Fdawgs/node-poppler/releases/latest/)
[](https://npmjs.com/package/node-poppler)
[](https://github.com/Fdawgs/node-poppler/actions/workflows/ci.yml)
[](https://coveralls.io/github/Fdawgs/node-poppler?branch=main)
[](https://github.com/prettier/prettier)
> Asynchronous Node.js wrapper for the Poppler PDF rendering library
## Overview
[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.
The `node-poppler` module provides an asynchronous Node.js wrapper around said utility binaries for easier use.
## Installation
Install using `npm`:
```bash
npm i node-poppler
```
### Linux and macOS/Darwin support
64-bit Windows binaries are provided via an optional dependency on the [`node-poppler-win32`](https://www.npmjs.com/package/node-poppler-win32) package.
For Linux and Mac users, the `poppler-data` and `poppler-utils` binaries binary will need to be installed separately.
An example of downloading the binaries on a Debian system:
```
sudo apt-get install poppler-data poppler-utils
```
For macOS users, the binaries can be installed with [Homebrew](https://brew.sh/):
```
brew install poppler
```
## Example usage
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.
### poppler.pdfToCairo
Example of an `async` `await` call to `poppler.pdfToCairo()`, to convert only the first and second page of a PDF file to PNG:
```js
const { Poppler } = require("node-poppler");
const file = "test_document.pdf";
const poppler = new Poppler();
const options = {
firstPageToConvert: 1,
lastPageToConvert: 2,
pngFile: true,
};
const outputFile = `test_document.png`;
const res = await poppler.pdfToCairo(file, outputFile, options);
console.log(res);
```
Example of an `async` `await` call to `poppler.pdfToCairo()`, to convert only the first page of a PDF file to a new
PDF file using stdout:
```js
const { writeFile } = require("node:fs/promises");
const { Poppler } = require("node-poppler");
const file = "test_document.pdf";
const poppler = new Poppler();
const options = {
lastPageToConvert: 1,
pdfFile: true,
};
const res = await poppler.pdfToCairo(file, undefined, options);
// pdfToCairo writes to stdout using binary encoding if pdfFile or singleFile options are used
await writeFile("new_file.pdf", res, { encoding: "binary", flush: true });
```
### poppler.pdfToHtml
Example of calling `poppler.pdfToHtml()` with a promise chain:
```js
const { Poppler } = require("node-poppler");
const file = "test_document.pdf";
const poppler = new Poppler();
const options = {
firstPageToConvert: 1,
lastPageToConvert: 2,
};
poppler
.pdfToHtml(file, undefined, options)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
throw err;
});
```
Example of calling `poppler.pdfToHtml()` with a promise chain, providing a Buffer as an input:
```js
const { readFileSync } = require("node:fs");
const { Poppler } = require("node-poppler");
const file = readFileSync("test_document.pdf");
const poppler = new Poppler();
const options = {
firstPageToConvert: 1,
lastPageToConvert: 2,
};
poppler
.pdfToHtml(file, "tester.html", options)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
throw err;
});
```
### poppler.pdfToText
Example of calling `poppler.pdfToText()` with a promise chain:
```js
const { Poppler } = require("node-poppler");
const file = "test_document.pdf";
const poppler = new Poppler();
const options = {
firstPageToConvert: 1,
lastPageToConvert: 2,
};
const outputFile = "test_document.txt";
poppler
.pdfToText(file, outputFile, options)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
throw err;
});
```
## Contributing
Contributions are welcome, and any help is greatly appreciated!
See [the contributing guide](https://github.com/Fdawgs/.github/blob/main/CONTRIBUTING.md) for details on how to get started.
Please adhere to this project's [Code of Conduct](https://github.com/Fdawgs/.github/blob/main/CODE_OF_CONDUCT.md) when contributing.
## Acknowledgements
- [**Albert Astals Cid**](https://github.com/albert-astals-cid-kdab) - [Poppler](https://poppler.freedesktop.org/) developer
## License
`node-poppler` is licensed under the [MIT](./LICENSE) license.