Skip to footer content
USING IRONPDF

How to Convert a PDF to an Image in C#

Converting PDFs to images in C# is pretty common. You might want thumbnails, web previews, or even archive copies. With IronPDF, this process is 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 makes sure 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

How to Convert a PDF to an Image in C#: Figure 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:

How to Convert a PDF to an Image in C#: Figure 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.

How to Convert a PDF to an Image in C#: Figure 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.

How to Convert a PDF to an Image in C#: Figure 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 for unlimited conversions and priority support.

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of ...Read More