Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
node-poppler
Advanced tools
Asynchronous node.js wrapper for the Poppler PDF rendering library
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.
Install using npm
:
npm i node-poppler
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
sudo apt-get install poppler-utils
For macOS users, you can download the latest versions with Homebrew:
brew install poppler
Once they have been installed, you will need to pass the poppler-utils
installation directory as a parameter to an instance of the Poppler class:
const { Poppler } = require("node-poppler");
const poppler = new Poppler("/usr/bin");
const { Poppler } = require("node-poppler");
API Documentation can be found here
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" });
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;
});
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,
};
poppler
.pdfToText(file, options)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
throw err;
});
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.
node-poppler
is licensed under the MIT license.
FAQs
Asynchronous node.js wrapper for the Poppler PDF rendering library
The npm package node-poppler receives a total of 7,870 weekly downloads. As such, node-poppler popularity was classified as popular.
We found that node-poppler demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.