Rasterize a PDF to Images

IronPDF for Python can rasterize PDF pages into image files or in-memory bitmap objects — useful for generating thumbnails, previews, or image-based exports.

Getting Started

Load a PdfDocument from a file using PdfDocument.FromFile, then call one of the rasterization methods to convert its pages to images.

Understanding the Code

  • RasterizeToImageFiles(pattern): Exports all pages as image files to the specified folder. The filename pattern supports a wildcard (*) that is replaced with the page index. Common formats such as .png and .jpg are supported based on the file extension used in the pattern.
  • RasterizeToImageFiles(pattern, width, height): The optional width and height parameters (in pixels) set the output image dimensions, letting you control the resolution of the exported images.
  • ToBitmap(): Converts all PDF pages to a list of in-memory AnyBitmap objects. These can be processed further in Python without writing to disk.

Choosing an Output Format

  • Use .png in the path pattern for lossless images suitable for document archiving or OCR preprocessing.
  • Use .jpg for smaller file sizes when image quality is less critical, such as web thumbnails.

Page Ranges

To rasterize only specific pages, use RasterizeToImageFiles with an explicit page range overload rather than processing the full document, reducing memory usage for large PDFs.

Learn how to convert PDFs to images with IronPDF for Python!

Ready to Get Started?
Version: 2026.6 just released
Still Scrolling Icon

Still Scrolling?

Want proof fast?
run a sample watch your HTML become a PDF.