npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-poppler

v7.2.2

Published

Asynchronous node.js wrapper for the Poppler PDF rendering library

Downloads

43,670

Readme

node-poppler

GitHub release npm version Build status Coverage status code style: Prettier

Asynchronous node.js wrapper for the Poppler PDF rendering library

Overview

Poppler 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:

npm i node-poppler

Linux and macOS/Darwin support

Windows binaries are provided with this repository. For Linux users, you will need to download the poppler-data and poppler-utils binaries separately.

An example of downloading the binaries on a Debian system:

sudo apt-get install poppler-data poppler-utils

For macOS users, you can download the latest versions with Homebrew:

brew install poppler

Example usage

Please refer to the JSDoc comments in the source code or the generated type definitions 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:

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 of a PDF file to a new PDF file using stdout:

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" });

poppler.pdfToHtml

Example of calling poppler.pdfToHtml() with a promise chain:

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:

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:

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 for details on how to get started. Please adhere to this project's Code of Conduct when contributing.

Acknowledgements

License

node-poppler is licensed under the MIT license.