Rasterize a PDF to Images

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.edit.PageSelection;
import com.ironsoftware.ironpdf.image.ToImageOptions;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;

PdfDocument pdf = PdfDocument.fromFile(Paths.get("assets/composite.pdf"));

// Extract all the pages from the PDF file.
List<BufferedImage> extractedImages = pdf.toBufferedImages();

// With the ToImageOptions object, specify maximum image dimensions for each
// extracted image, as well as their DPI
ToImageOptions rasterOptions = new ToImageOptions();
rasterOptions.setImageMaxHeight(100);
rasterOptions.setImageMaxWidth(100);

// Call the toBufferedImage method along with a PageSelection object to choose the pages from which to
// extract the images
//
// Available PageSelection methods include: allPages, lastPage, firstPage, singlePage(int pageIndex),
// and pageRange(int startingPage, int endingPage)
List<BufferedImage> sizedExtractedImages = pdf.toBufferedImages(rasterOptions, PageSelection.allPages());

// Save all the extracted images to a file location
int i = 1;
for (BufferedImage extractedImage : sizedExtractedImages) {
    String fileName = "assets/images/" + i++ + ".png";
    ImageIO.write(extractedImage, "PNG", new File(fileName));
}
mvn install
Rasterize a PDF to Images

Rasterize a PDF to Images

Once loaded from a file, converted from source content (webpages, URLs, HTML, etc.), IronPDF can export pages of PDF documents into images that can be saved to a file system, stored in a database, or sent over networks (among other uses).

The toBufferedImages method returns a List containing a collection of BufferedImage objects. Each BufferedImage contains the image byte content for a single page of the original PdfDocument. Moreover, the BufferedImage List is arranged in ascending order by page number. Developers can include a PageSelection object as an argument in the method call to generate this List for an inclusive set of pages in the PDF.

The featured code example creates a ToImageOptions object to set the expected width and height of the images post-conversion. This class also includes a method for changing the DPI of the image output (setDpi). The developer can pair together instances of this class along with that of the PageSelection to control the scope, size, and quality of PDF-to-Image conversion simultaneously.

For additional information about IronPDF and its capabilities, you can visit the IronPDF Documentation and Resources.

Learn more about the toBufferedImages method here.
View on GitHub

Ready to Get Started?

Version:2026.10just released