pdf-to-png-converter
A Node.js utility to convert PDF file/buffer pages to PNG files/buffers without binary and OS dependencies. This utility is ideal for applications that need to process and convert PDF documents into image formats for easier viewing, sharing, or further image processing. It supports various options for rendering fonts, handling encrypted PDFs, and specifying output details, making it a versatile tool for developers working with PDF files in different environments.
Getting Started
Package Installation
Installation:
npm install -D pdf-to-png-converter
Note: This package requires Node.js version 22 or higher.
Example
const { pdfToPng } = require('pdf-to-png-converter');
test(`Convert PDF To PNG`, async () => {
const pngPages = await pdfToPng(pdfFilePath, {
disableFontFace: false,
useSystemFonts: false,
enableXfa: false,
viewportScale: 2.0,
outputFolder: 'output/folder',
outputFileMaskFunc: (pageNum) => `page_${pageNum}.png`,
pdfFilePassword: 'pa$$word',
pagesToProcess: [1, 3, 11],
strictPagesToProcess: false,
verbosityLevel: 0
});
});
Output
The output of the pdfToPng
function is an array of objects with the following structure:
{
pageNumber: number;
name: string;
content: Buffer;
path: string;
width: number;
height: number;
}
Buy Me A Coffee
In case you want to support my work: