How to Convert a PDF to an Image File in Node.js
IronPDF for Node.js converts PDF pages to images with a single method call. The rasterizeToImageFiles method produces PNG, JPG, GIF, BMP, and other formats from any PDF -- single-page or multi-page -- with direct control over output resolution and page selection.
The method automatically detects the output format from the file extension you supply, so switching between formats requires no configuration changes. For environments where the extension cannot be changed, an explicit ImageType enum value overrides the extension-based detection. The IronPDF Node.js documentation covers the full range of supported input sources, including file paths, byte buffers, and HTML strings converted to PDF before rasterization.
Quickstart: Convert PDF to PNG
- Install IronPDF:
npm install @ironsoftware/ironpdf - Import
PdfDocumentfrom the package - Load your PDF with
PdfDocument.fromFile() - Call
rasterizeToImageFiles()with the output path
//:path=/static-assets/pdf/content-code-examples/how-to/nodejs-pdf-to-image/quickstart.js
import { PdfDocument } from "@ironsoftware/ironpdf";
PdfDocument.fromFile("./sample.pdf").then((pdf) => {
pdf.rasterizeToImageFiles("./output.png");
});Minimal Workflow (5 steps)
1. Install IronPDF for Node.js via npm 2. Import the `PdfDocument` class 3. Load a PDF file using `PdfDocument.fromFile()` 4. Call `rasterizeToImageFiles()` with the desired output path and extension 5. For multi-page PDFs, the method appends page numbers to each output filename automaticallyHow Do I Install IronPDF for Node.js?
npm install @ironsoftware/ironpdfnpm install @ironsoftware/ironpdfInstall IronPDF's Node.js package from npm to convert PDFs to PNG, JPG, GIF, BMP, and other image formats.
Before converting PDFs to images in production, configure your license key. The package also requires the IronPDF Engine to be installed on your system — this binary handles all PDF rendering operations and must be present for conversion to function.
What Are the System Requirements?
Node.js 12 or later is required. The IronPDF Engine binary is downloaded automatically the first time the package loads, but you can also install it manually if your deployment environment restricts outbound network access. The @ironsoftware/ironpdf package is available on the npm registry and carries no native module compilation step, which keeps CI pipelines straightforward.
How Do I Convert a PDF to an Image?
The rasterizeToImageFiles method reads a PDF document and writes one image file per page to the output path you provide. For single-page PDFs, it produces exactly one image. For multi-page PDFs, it appends a page number suffix to each filename automatically.
The example below loads a sample PDF from Learning Container and converts it to a PNG file.
The sample PDF file opened in a viewer. Download this file and other test PDFs from Learning Container.
//:path=/static-assets/pdf/content-code-examples/how-to/nodejs-pdf-to-image/convert-to-png.js
import { PdfDocument } from "@ironsoftware/ironpdf";
// Load the PDF and convert it to a PNG image.
// The output path determines the format — change .png to .jpg for JPEG output.
PdfDocument.fromFile("./sample-pdf-file.pdf").then((pdf) => {
pdf.rasterizeToImageFiles("./images/sample-pdf-file.png");
return pdf;
}).catch((error) => {
console.error("Error converting PDF to image:", error);
});PdfDocument.fromFile loads the PDF and returns a Promise resolving to a PdfDocument object. The .then callback receives the resolved document and calls rasterizeToImageFiles with the destination path. The file extension in the path — .png here — tells IronPDF which format to produce. The .catch block handles any read or conversion errors.
The PNG generated from the sample PDF above. IronPDF converts the document in three lines of code.
For more detailed examples of this method's options, see the PDF to Images code example page.
How Do I Convert a PDF to JPEG Format?
Format selection is automatic: whatever extension you pass to rasterizeToImageFiles determines the output format. To produce a JPEG instead of a PNG, change the extension in the destination path:
//:path=/static-assets/pdf/content-code-examples/how-to/nodejs-pdf-to-image/convert-to-jpeg-extension.js
// Switch to JPEG by changing the file extension in the output path.
pdf.rasterizeToImageFiles("./images/pdf-to-jpeg.jpg");When the output filename cannot be controlled — for example, in automated pipelines with fixed naming schemes — pass an ImageType value in the options object to override extension-based detection:
//:path=/static-assets/pdf/content-code-examples/how-to/nodejs-pdf-to-image/convert-to-jpeg-imagetype.js
import { PdfDocument, ImageType } from "@ironsoftware/ironpdf";
// ImageType.JPG forces JPEG output regardless of the file extension.
const options = {
type: ImageType.JPG,
dpi: 300
};
PdfDocument.fromFile("./sample-pdf-file.pdf").then((pdf) => {
pdf.rasterizeToImageFiles("./images/output.png", options);
return pdf;
});The type property in the options object takes precedence over the filename extension. In the example above, rasterizeToImageFiles produces a JPEG file even though the destination path ends with .png. The same pattern applies to GIF and BMP outputs.
How Do DPI Settings Affect Output Quality?
The dpi property in the options object controls the pixel density of the rasterized output. Higher values produce larger files with more detail; lower values reduce file size at the cost of sharpness.
dpi: 300 produces print-quality images suitable for high-resolution printing or archiving. For screen display or thumbnail generation, dpi: 96 reduces file size while maintaining adequate clarity for web use.A DPI of 150 is a reasonable default for most archive or preview scenarios — the output is crisp enough for reading on screen and the file sizes remain manageable. For content that will be printed or subjected to OCR processing after conversion, 300 DPI or higher is preferred.
How Do I Convert a Multi-Page PDF to Images?
For documents with more than one page, rasterizeToImageFiles creates one image per page. IronPDF appends a zero-based page index to each output filename, keeping the output organized without additional code on your part.
A two-page sample PDF. IronPDF creates one image file per page during conversion.
//:path=/static-assets/pdf/content-code-examples/how-to/nodejs-pdf-to-image/convert-multipage.js
import { PdfDocument } from "@ironsoftware/ironpdf";
// Each page of the PDF becomes a separate image file.
// Output filenames: multipage-pdf-page_1.png, multipage-pdf-page_2.png, etc.
PdfDocument.fromFile("./multipage-pdf.pdf").then((pdf) => {
pdf.rasterizeToImageFiles("./images/multipage-pdf/multipage-pdf-page.png");
});
The two PNG files produced from the two-page PDF. IronPDF names each output file with its page number.
This automatic page-splitting behavior works with all supported image formats. Pair it with the fromPages option in the next section to convert only specific pages from large documents. For working in the opposite direction, the image to PDF example shows how to combine multiple image files into a single PDF document.
How Are Output Filenames Structured?
The filename pattern uses a one-based page number appended before the file extension. If the output path is ./images/report-page.png, a three-page PDF produces report-page_1.png, report-page_2.png, and report-page_3.png. The output directory must exist before calling rasterizeToImageFiles — the method does not create missing directories automatically.
rasterizeToImageFiles. The method throws an error if the target directory does not exist. Use Node.js's fs.mkdirSync('./images/output', { recursive: true }) to create it in advance.How Do I Convert Only Specific Pages?
The fromPages property in the options object accepts an array of zero-based page indexes. Only the specified pages are rasterized; all others are skipped. This is useful when working with large PDFs where only a subset of pages is needed — for instance, extracting cover and section-start pages for a document preview. When you need to work with individual pages before converting them, the Node.js API reference for PdfDocument documents additional page-level operations.
//:path=/static-assets/pdf/content-code-examples/how-to/nodejs-pdf-to-image/convert-selective-pages.js
import { PdfDocument, ImageType } from "@ironsoftware/ironpdf";
// Convert only pages 1, 4, 6, and 9 (zero-indexed: 0, 3, 5, 8) to BMP.
const options = {
type: ImageType.BMP,
fromPages: [0, 3, 5, 8],
dpi: 150
};
PdfDocument.fromFile("./sample-pdf-with-images.pdf").then((pdf) => {
pdf.rasterizeToImageFiles(
"./images/multipage-selective-pdf/multipage-pdf-page.bmp",
options
);
}).catch((error) => {
console.error("Failed to convert pages:", error);
});
IronPDF rasterized only the four pages specified in the fromPages array. The other pages were not processed.
Page indexes in fromPages are zero-based, so [0, 3, 5, 8] targets the first, fourth, sixth, and ninth pages. The DPI value of 150 balances output quality against file size — suitable for archive or preview use cases. Selective conversion is compatible with all supported image types.
What Is the Difference Between Zero-Based and One-Based Page Numbers?
fromPages uses zero-based indexing, matching JavaScript's standard array convention. Page 1 of the document corresponds to index 0, page 2 to index 1, and so on. This differs from the one-based page numbers that appear in PDF viewers. When translating viewer page numbers to fromPages indexes, subtract one from each page number.
pdf.pageCount() from the PdfDocument API and use [pdf.pageCount() - 1] as the fromPages value.What Are the Next Steps for PDF-to-Image Conversion?
IronPDF's rasterizeToImageFiles method handles format selection, multi-page splitting, and selective page conversion in a consistent API. The options object is the single extension point for format overrides, DPI control, and page filtering.
To go further, the IronPDF Node.js API reference documents all parameters available on rasterizeToImageFiles and the PdfDocument class. The PDF to Images code example shows rasterizeToImageFiles used with additional configuration. To work in the opposite direction, see converting images to PDF files or converting multi-frame TIFF files to PDF.
Start your free trial of IronPDF for Node.js to test PDF-to-image conversion in your own project. View licensing options to find the plan that fits your team.
Ready to see what else IronPDF can do? Check out the full Node.js tutorial here: HTML to PDF in Node.js
Frequently Asked Questions
How do I convert a PDF to an image in Node.js?
Use IronPDF's rasterizeToImageFiles method. Install the package with npm install @ironsoftware/ironpdf, load your PDF using PdfDocument.fromFile(), then call rasterizeToImageFiles() with the output path. The file extension determines the output format automatically.
What image formats does rasterizeToImageFiles support?
IronPDF supports PNG, JPG, GIF, and BMP output. The format is detected from the file extension in the output path. To override this, pass an ImageType enum value in the options object: for example, { type: ImageType.JPG } forces JPEG output regardless of the filename extension.
How do I convert only specific pages of a PDF to images?
Pass a fromPages array in the options object. The array accepts zero-based page indexes, so fromPages: [0, 2, 4] converts the first, third, and fifth pages. Pages not listed in the array are skipped.
What DPI should I use for PDF to image conversion?
Set the dpi property in the options object. Use dpi: 96 for screen display and thumbnails, dpi: 150 for archive and preview use cases, and dpi: 300 for print-quality output or content that will be processed by OCR after conversion.
What are the installation requirements for IronPDF in Node.js?
Node.js 12 or later is required. Install the package with npm install @ironsoftware/ironpdf. The IronPDF Engine binary downloads automatically on first use and handles all PDF rendering. For production use, configure a license key to remove watermarks from output.
How are output filenames structured for multi-page PDFs?
IronPDF appends a one-based page number before the file extension. If the output path is report-page.png, a three-page PDF produces report-page_1.png, report-page_2.png, and report-page_3.png. The output directory must exist before calling the method.
Is the PDF to image conversion asynchronous in Node.js?
Yes. Both PdfDocument.fromFile() and rasterizeToImageFiles() return Promises. Chain .then() for the success path and .catch() to handle conversion errors. You can also use async/await syntax with these methods.





