How to Convert PDF to Image in Python | IronPDF

Python PDF to Image Conversion

PDF-to-image conversion is a common requirement in Python applications. Developers use it to generate document thumbnails, web previews, and to feed PDF content into image processing pipelines. IronPDF for Python provides the RasterizeToImageFiles method, which converts any PDF document (or URL) into JPEG, PNG, or TIFF image files with configurable DPI and dimensions.

This guide shows how to convert PDF files to images in Python, how to control output quality, and how to size the resulting images to fit layout constraints.

Quickstart: Convert a PDF to Images

  1. Install IronPDF: pip install ironpdf
  2. Load a PDF document: pdf = PdfDocument.FromFile("document.pdf")
  3. Convert every page to a PNG: pdf.RasterizeToImageFiles("output/*.png", DPI=96)
#:path=/static-assets/pdf/content-code-examples/how-to/python-pdf-to-image/quickstart.py
from ironpdf import PdfDocument

pdf = PdfDocument.FromFile("document.pdf")
pdf.RasterizeToImageFiles("output/*.png", DPI=96)
#:path=/static-assets/pdf/content-code-examples/how-to/python-pdf-to-image/quickstart.py
from ironpdf import PdfDocument

pdf = PdfDocument.FromFile("document.pdf")
pdf.RasterizeToImageFiles("output/*.png", DPI=96)
PYTHON

Why Do Developers Convert PDFs to Images?

PDF-to-image conversion solves several practical problems in software development. The most common requirement is preview generation -- displaying a thumbnail of a PDF document in a web interface or mobile application without forcing users to download and open the full file.

Other frequent use cases include:

  • Machine learning pipelines: OCR models, layout analysis tools, and computer vision systems accept image inputs, not PDFs
  • Archival and compliance: Storing a visual snapshot alongside the original PDF ensures long-term readability even when PDF viewers change
  • Report embedding: Including specific PDF pages as images inside other documents or email templates
  • Automated testing: Comparing rendered page snapshots to detect visual regressions in PDF output

Python does not include native PDF-to-image functionality in its standard library. Tools like pdf2image require installing Poppler as an external binary, which adds deployment complexity. IronPDF handles rendering internally, so adding PDF-to-image conversion to any Python project requires only a single pip install.

Please noteIronPDF uses a Chromium-based rendering engine. HTML-rendered PDFs produce images that look identical to what a browser would display, which is useful when PDFs originate from HTML or URL sources.

How Do I Convert a PDF File to Images?

To convert a PDF to images, call RasterizeToImageFiles on a PdfDocument instance. The method writes one image file per page to the specified directory. The asterisk (*) in the output path is replaced by the page number starting from 1, so assets/images/*.png produces assets/images/1.png, assets/images/2.png, and so on.

Create the output directory before calling the method. IronPDF will not create it automatically if it does not exist.

#:path=/static-assets/pdf/content-code-examples/how-to/python-pdf-to-image/convert-pdf-to-images.py
from ironpdf import PdfDocument

# Load a PDF from disk
pdf = PdfDocument.FromFile("my-content.pdf")

# Write each page to a PNG file in the "assets/images" folder
# The folder must exist before calling this method
pdf.RasterizeToImageFiles("assets/images/*.png", DPI=96)
#:path=/static-assets/pdf/content-code-examples/how-to/python-pdf-to-image/convert-pdf-to-images.py
from ironpdf import PdfDocument

# Load a PDF from disk
pdf = PdfDocument.FromFile("my-content.pdf")

# Write each page to a PNG file in the "assets/images" folder
# The folder must exist before calling this method
pdf.RasterizeToImageFiles("assets/images/*.png", DPI=96)
PYTHON

The DPI parameter controls image resolution. A higher DPI produces a sharper image at the cost of larger file size and longer processing time. Standard values:

DPI Values and Typical Use Cases
DPITypical Use
72Screen resolution, fast processing
96Standard web quality
150Good print quality
300High-quality print output
File explorer showing numbered PNG output files (1.png through 11.png) generated by RasterizeToImageFiles from an 11-page PDF

Output directory with one PNG file per PDF page

If output images appear blurry, increase the DPI value. Processing 300 DPI across a 50-page document takes noticeably longer than 96 DPI -- choose based on the actual quality requirements for the use case.

TipsFor web thumbnail generation, 96 DPI is sufficient and keeps file sizes small. Reserve 150-300 DPI for cases where the image will be printed or displayed at full size.

How Do I Convert a Specific Page Range to Images?

To convert only a subset of pages, pass the page indices as the second argument to RasterizeToImageFiles. Page indices are zero-based integers.

#:path=/static-assets/pdf/content-code-examples/how-to/python-pdf-to-image/convert-page-range.py
from ironpdf import PdfDocument

pdf = PdfDocument.FromFile("my-content.pdf")

# Convert only pages 1, 2, and 3 (zero-based indices: 0, 1, 2)
pdf.RasterizeToImageFiles("assets/images/*.png", [0, 1, 2], DPI=96)
#:path=/static-assets/pdf/content-code-examples/how-to/python-pdf-to-image/convert-page-range.py
from ironpdf import PdfDocument

pdf = PdfDocument.FromFile("my-content.pdf")

# Convert only pages 1, 2, and 3 (zero-based indices: 0, 1, 2)
pdf.RasterizeToImageFiles("assets/images/*.png", [0, 1, 2], DPI=96)
PYTHON

Selective page extraction is useful for documents where only the first few pages need to be previewed, avoiding unnecessary processing of the entire file. For workflows that extract images already embedded in a PDF, IronPDF provides separate extraction methods.

How Do I Convert a URL to Images?

IronPDF can render a web page to a PDF and then convert that PDF to images in a single workflow. Use ChromePdfRenderer to fetch and render the URL, then call RasterizeToImageFiles on the resulting PdfDocument. This approach creates visual archives of web pages or generates preview images for web-based content without requiring a separate screenshot tool.

#:path=/static-assets/pdf/content-code-examples/how-to/python-pdf-to-image/url-to-images.py
from ironpdf import ChromePdfRenderer

# Render a web page to PDF
renderer = ChromePdfRenderer()
pdf = renderer.RenderUrlAsPdf("https://www.example.com")

# Convert each rendered page to a PNG image
pdf.RasterizeToImageFiles("assets/images/*.png", DPI=96)
#:path=/static-assets/pdf/content-code-examples/how-to/python-pdf-to-image/url-to-images.py
from ironpdf import ChromePdfRenderer

# Render a web page to PDF
renderer = ChromePdfRenderer()
pdf = renderer.RenderUrlAsPdf("https://www.example.com")

# Convert each rendered page to a PNG image
pdf.RasterizeToImageFiles("assets/images/*.png", DPI=96)
PYTHON

The rendered images reflect how the page appears in a Chromium browser, including CSS styles and JavaScript-rendered content. For pages behind authentication or requiring interaction, consider using IronPDF's HTML to PDF tutorial to supply the pre-rendered markup directly. The resulting PDF can then be rasterized using the same approach shown above.

File explorer showing 5 PNG files (1.png through 5.png) generated from a URL rendered to PDF by IronPDF

Images generated from a URL rendered through IronPDF

How Do I Control Output Image Dimensions?

By default, RasterizeToImageFiles generates images at the native page dimensions scaled by the DPI factor. To constrain the output size, set ImageMaxWidth and ImageMaxHeight, both measured in pixels.

IronPDF preserves the original aspect ratio based on the ImageMaxHeight value. The output will not be stretched or distorted even if the specified width and height have a different ratio than the source page.

#:path=/static-assets/pdf/content-code-examples/how-to/python-pdf-to-image/constrained-dimensions.py
from ironpdf import PdfDocument

pdf = PdfDocument.FromFile("my-content.pdf")

# Generate thumbnail images constrained to 500x500 pixels
pdf.RasterizeToImageFiles(
    "assets/images/*.png",
    ImageMaxWidth=500,
    ImageMaxHeight=500,
    DPI=200
)
#:path=/static-assets/pdf/content-code-examples/how-to/python-pdf-to-image/constrained-dimensions.py
from ironpdf import PdfDocument

pdf = PdfDocument.FromFile("my-content.pdf")

# Generate thumbnail images constrained to 500x500 pixels
pdf.RasterizeToImageFiles(
    "assets/images/*.png",
    ImageMaxWidth=500,
    ImageMaxHeight=500,
    DPI=200
)
PYTHON

Setting ImageMaxWidth=500, ImageMaxHeight=500 at 200 DPI produces images suitable for thumbnail displays or card-based UI layouts. Adjust these values to match the dimensions required by the application design. To generate the PDF content being rasterized, IronPDF also supports creating PDFs from Python and merging multiple PDFs before conversion.

ImportantAspect ratio is preserved based on height. If the source page is wider than tall, the resulting image may be narrower than ImageMaxWidth. Design layouts to handle variable-width thumbnails.

What Are the Next Steps for PDF to Image Conversion?

This guide covered three core workflows: converting a PDF file to images, converting a URL to images, and controlling image dimensions and quality. IronPDF supports JPEG, JPG, PNG, TIFF, and additional formats through the same RasterizeToImageFiles method. Change the file extension in the output path pattern to switch formats.

For further automation, consider these next steps:

  • Batch processing: Loop over a directory of PDFs and convert each one in sequence, or use Python's concurrent.futures module for parallel processing
  • Selective extraction: Use the page index parameter to extract only the pages relevant to the use case
  • Image pipeline integration: Feed the output files into PIL/Pillow or OpenCV for further processing such as cropping, annotation, or format normalization
  • Compression before conversion: Use IronPDF's PDF compression to reduce file size before rasterizing large documents
  • Form workflows: Fill PDF forms programmatically and then convert the completed form pages to images for review or archival

To continue building with IronPDF, explore the IronPDF for Python documentation and the rasterize PDF to images example.

Start a free 30-day trial of IronPDF for Python to use these features in production. When ready to deploy, view licensing options for the plan that fits the project scale.

Please noteFurther Reading: Converting PDFs to Images

Frequently Asked Questions

How do I convert a PDF to an image in Python?

Install IronPDF with pip install ironpdf, then load the PDF using PdfDocument.FromFile("file.pdf") and call RasterizeToImageFiles("output/*.png", DPI=96). This writes one image per page to the specified directory.

What image formats does IronPDF support for PDF conversion?

IronPDF supports PNG, JPEG, JPG, and TIFF output formats. Specify the format by changing the file extension in the output path pattern passed to RasterizeToImageFiles, such as *.jpg for JPEG or *.tiff for TIFF.

How do I control the image quality when converting a PDF?

Use the DPI parameter in RasterizeToImageFiles. A value of 96 is standard web quality. 150 suits print previews. 300 produces high-quality print output. Higher DPI values increase file size and processing time.

Can I set a maximum width or height for the output images?

Yes. Pass ImageMaxWidth and ImageMaxHeight in pixels to RasterizeToImageFiles. IronPDF preserves the aspect ratio based on the height value, so the image will not be distorted.

How do I convert only specific pages from a PDF to images?

Pass a list of zero-based page indices as the second argument to RasterizeToImageFiles. For example, [0, 1, 2] converts the first three pages only.

Can I convert a web page URL to images using IronPDF?

Yes. Use ChromePdfRenderer to call RenderUrlAsPdf with the URL, which returns a PdfDocument. Then call RasterizeToImageFiles on that document to produce image files from each rendered page.

Does IronPDF require any external binaries for PDF to image conversion?

No. IronPDF includes its own Chromium-based rendering engine and does not require Poppler, Ghostscript, or any external binary installation. A pip install ironpdf is sufficient to get started.

Why do my converted images appear blurry?

Blurry output is caused by a low DPI value. Increase it from the default 96 to 150 or 300 for sharper results. Note that higher DPI produces larger file sizes and takes longer to process.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Version: 2026.5 just released
Still Scrolling Icon

Still Scrolling?

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