Skip to footer content
USING IRONOCR

C# Convert PDF to Image: Complete Developer Guide

Converting PDFs to images in C# is pretty common. You might want thumbnails, web previews, or even archive copies. With IronPDF, this process becomes an easy task. This is thanks to its RasterizeToImageFiles method, which lets you convert PDF files into image files like PNG images, JPEG images, TIFF images, or BMP with just a few lines of code.

In this article, we’ll walk through everything you need to know to convert PDFs to PNG, JPG, TIFF, or BMP. You’ll see how to handle full documents, specific page ranges, and even web pages rendered as PDFs. By the end, you’ll have a solid workflow for generating high-quality images from PDFs in your .NET projects.

Why Convert PDF Documents to Images in C#?

Converting PDF pages to images has practical applications in modern .NET Framework or .NET apps. Document management systems need thumbnails for fast visual navigation, while web apps benefit from image formats for better browser compatibility and faster load times.

Additionally, converting PDFs to images ensures your PDF looks right on any platform with limited PDF library support. Whether you’re working with multiple pages or a single page, IronPDF handles this process in just a few lines of code without worrying about errors or complicated rendering.

Getting Started with IronPDF

First, create a new C# console application in Visual Studio and install IronPDF via NuGet Package Manager:

Install-Package IronPDF

C# Convert PDF to Image: Complete Developer Guide: Image 1 - IronPDF being Installed via the NuGet Package Manager Console

IronPDF supports .NET Framework, .NET Core, and .NET 5+, ensuring your PDF to images workflow is compatible with any version of .NET you're using. Once installed, you can start converting PDF pages to image files in your program.

How to Convert PDF Pages to Image Files?

The simplest way to convert a PDF to images involves loading the document and calling the RasterizeToImageFiles method:

using IronPdf;
class Program
{
    static void Main(string[] args)
    {
        // Load an existing PDF document
        var pdfDocument = PdfDocument.FromFile("report.pdf");
        // Convert all pages to PNG images
        pdfDocument.RasterizeToImageFiles(@"C:\images\page_*.png");
    }
}
using IronPdf;
class Program
{
    static void Main(string[] args)
    {
        // Load an existing PDF document
        var pdfDocument = PdfDocument.FromFile("report.pdf");
        // Convert all pages to PNG images
        pdfDocument.RasterizeToImageFiles(@"C:\images\page_*.png");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This code converts each page of the PDF into a separate PNG file. The asterisk (*) in the filename pattern gets replaced with the page number automatically. For proper resource management, wrap the PdfDocument in a using statement to ensure disposal.

After running the code, we can see in the output directory that even though our PDF has multiple pages within it, our code doesn't specify what pages to convert, so each one has been saved as an individual image file:

C# Convert PDF to Image: Complete Developer Guide: Image 2 - PDF to Image example for converting all pages

For converting specific pages, specify the page range:

// Specify the page indexes for conversion
int[] pageIndexes = new[] { 0, 1, 2 };
// Convert pages 1-3 to JPG images
pdfDocument.RasterizeToImageFiles(@"C:\images\page_*.jpg", pageIndexes);
// Specify the page indexes for conversion
int[] pageIndexes = new[] { 0, 1, 2 };
// Convert pages 1-3 to JPG images
pdfDocument.RasterizeToImageFiles(@"C:\images\page_*.jpg", pageIndexes);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Note that page indexing starts at 0, so the first page has pageIndex = 0.

C# Convert PDF to Image: Complete Developer Guide: Image 3 - Specified PDF pages converted to image

How to Control Image Quality?

Image quality directly impacts file size and visual clarity. IronPDF lets you control this through DPI (dots per inch) settings:

// High-quality conversion at 300 DPI
pdfDocument.RasterizeToImageFiles(@"C:\images\high_quality_*.png", DPI: 300);
// Web-optimized at 150 DPI
pdfDocument.RasterizeToImageFiles(@"C:\images\web_*.jpg", DPI: 150);
// High-quality conversion at 300 DPI
pdfDocument.RasterizeToImageFiles(@"C:\images\high_quality_*.png", DPI: 300);
// Web-optimized at 150 DPI
pdfDocument.RasterizeToImageFiles(@"C:\images\web_*.jpg", DPI: 150);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The default 96 DPI works for basic previews, but increase it to 150-300 DPI for print-quality images. Higher DPI values produce sharper images but larger file sizes.

C# Convert PDF to Image: Complete Developer Guide: Image 4 - High-quality converted PDF beside the original

Which Image Formats Are Supported?

IronPDF supports multiple image formats through the ImageType parameter:

// Convert to different formats
pdfDocument.RasterizeToImageFiles(@"C:\images\output_*.png", IronPdf.Imaging.ImageType.Png);
pdfDocument.RasterizeToImageFiles(@"C:\images\output_*.jpg", IronPdf.Imaging.ImageType.Jpeg);
pdfDocument.RasterizeToImageFiles(@"C:\images\output_*.tiff", IronPdf.Imaging.ImageType.Tiff);
pdfDocument.RasterizeToImageFiles(@"C:\images\output_*.bmp", IronPdf.Imaging.ImageType.Bitmap);
// Convert to different formats
pdfDocument.RasterizeToImageFiles(@"C:\images\output_*.png", IronPdf.Imaging.ImageType.Png);
pdfDocument.RasterizeToImageFiles(@"C:\images\output_*.jpg", IronPdf.Imaging.ImageType.Jpeg);
pdfDocument.RasterizeToImageFiles(@"C:\images\output_*.tiff", IronPdf.Imaging.ImageType.Tiff);
pdfDocument.RasterizeToImageFiles(@"C:\images\output_*.bmp", IronPdf.Imaging.ImageType.Bitmap);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Choose PNG for images requiring transparency, JPEG for photographs and web content, TIFF for archival purposes, and BMP when uncompressed images are needed. The IronPDF API reference provides detailed information about all supported ImageType options.

How to Handle Advanced Scenarios?

IronPDF excels at handling complex PDF to image conversion scenarios. One particularly useful feature is converting web pages directly to images via PDF rendering. For more HTML conversion options, explore the HTML to PDF conversion guide:

// Convert a webpage to images
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument webPdf = renderer.RenderUrlAsPdf("https://apple.com");
webPdf.RasterizeToImageFiles(@"C:\images\webpage_*.png", DPI: 200);
// Convert a webpage to images
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument webPdf = renderer.RenderUrlAsPdf("https://apple.com");
webPdf.RasterizeToImageFiles(@"C:\images\webpage_*.png", DPI: 200);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This approach captures dynamic web content perfectly, maintaining all styling and JavaScript-rendered elements.

For batch processing multiple PDFs, implement a simple loop:

string[] pdfFiles = Directory.GetFiles(@"C:\pdfs", "*.pdf");
foreach (string pdfPath in pdfFiles)
{
    using (var pdf = PdfDocument.FromFile(pdfPath))
    {
        string outputPath = Path.Combine(@"C:\images",
            Path.GetFileNameWithoutExtension(pdfPath) + "_*.png");
        pdf.RasterizeToImageFiles(outputPath);
    }
}
string[] pdfFiles = Directory.GetFiles(@"C:\pdfs", "*.pdf");
foreach (string pdfPath in pdfFiles)
{
    using (var pdf = PdfDocument.FromFile(pdfPath))
    {
        string outputPath = Path.Combine(@"C:\images",
            Path.GetFileNameWithoutExtension(pdfPath) + "_*.png");
        pdf.RasterizeToImageFiles(outputPath);
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Conclusion

IronPDF makes it easy to convert PDF documents into image files in C#. Whether you’re creating thumbnails, PNG images, JPEG images, or handling TIFF conversion for multiple pages, the RasterizeToImageFiles method handles everything.

You can customize output formats, control image quality with DPI settings, and even convert web pages rendered as PDFs into images, all without complex setup. For more advanced PDF features, check IronPDF's extensive documentation that includes sample code and explanations to explore everything IronPDF can do.

Ready to implement PDF to image conversion in your C# application? Start with a free trial to explore IronPDF's full capabilities, including watermark-free production testing for 30 days. Need to convert documents at scale? Consider a commercial license for unlimited conversions and priority support.

Frequently Asked Questions

How can I convert a PDF to an image in C#?

You can use the IronPDF library to convert a PDF to an image in C#. With the `RasterizeToImageFiles` method, you can easily convert PDF files into image formats like PNG, JPEG, TIFF, or BMP.

What image formats are supported by IronPDF for PDF conversion?

IronPDF supports several image formats when converting PDFs, including PNG, JPEG, TIFF, and BMP.

Is it possible to create thumbnails from a PDF using IronPDF?

Yes, you can create thumbnails from PDF documents using IronPDF by converting the PDFs into smaller-sized images, such as JPEG or PNG.

Can IronPDF convert entire PDF documents to images?

Yes, IronPDF can convert entire PDF documents to images, allowing you to save each page as an individual image file.

What is the `RasterizeToImageFiles` method in IronPDF?

The `RasterizeToImageFiles` method in IronPDF is used to convert PDF files into various image formats, such as PNG, JPEG, TIFF, and BMP, making it easy to create image representations of PDF content.

Why would I need to convert a PDF to an image in C#?

Converting a PDF to an image can be useful for creating thumbnails, web previews, or archiving purposes, enabling easier sharing and display of PDF content.

How many lines of code are needed to convert a PDF to an image using IronPDF?

You can convert a PDF to an image using IronPDF with just a few lines of code by utilizing the `RasterizeToImageFiles` method.

Kannaopat Udonpant
Software Engineer
Before becoming a Software Engineer, Kannapat completed a Environmental Resources PhD from Hokkaido University in Japan. While pursuing his degree, Kannapat also became a member of the Vehicle Robotics Laboratory, which is part of the Department of Bioproduction Engineering. In 2022, he leveraged his C# skills to join Iron Software's engineering ...
Read More