How to Convert PDF to PNG in C#

Updated June 28, 2023

In today's digital age, the need to convert PDF files to various image formats is becoming increasingly common. Whether you want to extract images from a PDF document, convert specific pages to PNG images, or manipulate PDF files in other ways, IronPDF provides a powerful solution for .NET developers.

In this article, we will explore the capabilities of IronPDF and demonstrate how to convert PDF files to PNG images using different approaches.

When it comes to generating detailed images from PDF files, rasterization is the ideal method. It allows you to obtain high-quality images with precise details and a wide range of colors. If you're searching for software that excels at rasterizing PDF files and converting them to images, IronPDF is the answer you've been seeking.

Converting PDF files to images serves various purposes in today's digital landscape. Whether it's preserving document formatting, facilitating online sharing, or extracting specific pages, the ability to convert PDFs to images proves invaluable. By converting PDFs to images, users gain flexibility, compatibility, and enhanced visual appeal, making it a vital step in many workflows.

Key Features of IronPDF's PDF-to-Images Rasterizing Solution

  • IronPDF offers a feature-rich solution for converting PDF files to raster images, packed with the following features:
  • Wide Range of Image Formats: IronPDF allows you to export image files in formats such as JPEG, PNG, BMP, and Bitmap. These formats are suitable for various use cases, including high-resolution prints and web publishing.
  • Individual Image Files for Each Page: The solution generates one image file per page, making it easy to manage and work with the resulting images.
  • Customizable Image Dimensions: You can specify the dimensions of the output images to best suit your project requirements.
  • Selective Page Conversion: IronPDF enables you to choose specific PDF pages or page ranges for conversion, providing flexibility and control over the process.
  • Easy Installation: The IronPDF library is straightforward to install, allowing you to start converting PDF files immediately.
  • Convenient Licensing Options: IronPDF offers quick and easy licensing options, simplifying the integration of the solution into your projects.
  • Outstanding Performance: IronPDF stands out among other PDF-to-raster file solutions, delivering exceptional performance and results.

IronPDF is a comprehensive PDF library for .NET applications that enables developers to work with PDF files programmatically. With its rich feature set and intuitive API, IronPDF simplifies the process of converting, manipulating, and interacting with PDF documents. It offers extensive support for different image formats, including PNG, JPEG, BMP, and TIFF.

IronPDF offers flexibility and control in converting PDF documents to PNG images programmatically. Whether you need to convert all the pages, extract images, or convert a specific page, IronPDF provides the necessary tools and methods to achieve your goals efficiently.

To get started with IronPDF, you can install it as a NuGet package in your .NET application. Simply search for "IronPdf" in the NuGet Package Manager or use the Package Manager Console to install the IronPDF library. Once installed, you can begin incorporating its functionality into your application.

In addition to the features discussed above, IronPDF offers various methods and options for customizing the PDF to PNG conversion process. For example, you can specify attributes such as image format, image quality, DPI, and page size. This allows you to tailor the output image according to your specific requirements.

Create C#

Creating a new console application project in Visual Studio involves the following steps:

  1. Open Visual Studio: Launch the Visual Studio IDE on your computer.
  2. Create a new project: From the "File" menu, select "New" and then "Project" from the dropdown menu. This will open a new screen.
  3. Choose the project type: In the "Create a new project" screen, select "Console App" and hit "Next" button.

    How to Convert PDF to PNG in C#: Figure 1

  4. Configure your new project: Click "Next" after selecting the appropriate template. In the next screen, you'll have to enter a name for your project, decide its location, and optionally choose a solution name if you plan on having multiple projects under the same solution.

    How to Convert PDF to PNG in C#: Figure 2

  5. Choose the target framework: After you click "Next", select the target framework for your project. Choose the .NET 7 version from the dropdown.

    How to Convert PDF to PNG in C#: Figure 3

  6. Create the project: Once configuring all the settings, click the "Create" button. Visual Studio will now create a new console application project with a Program.cs file containing a simple "Hello World" program by default.

Installing IronPDF in C#

To install IronPDF in a C# project, you can follow these steps

  1. Open your C# project in Visual Studio.
  2. Right-click on your project in the Solution Explorer and select "Manage NuGet Packages."
  3. In the NuGet Package Manager window, select the "Browse" tab.
  4. In the search box, type "IronPdf" and press Enter.
  5. Locate the IronPdf package in the search results and click on it.
  6. On the right-hand side, click the "Install" button to begin the installation process.
  7. Review the package installation details and click the "I Accept" button to accept the package's license terms.
  8. Visual Studio will download and install the IronPDF package and its dependencies into your project.
  9. Once the installation is complete, you can start using IronPDF in your C# code.

However, you can also install IronPDF using NuGet Package Manager Console using the following command:

Install-Package IronPdf

To verify that IronPDF is successfully installed, you can add a reference to the IronPdf namespace in your code file:

using IronPdf;
using IronPdf;
Imports IronPdf
VB   C#

This allows you to access the IronPDF classes, methods, and properties in your project.

You are now ready to utilize IronPDF's functionality to work with PDF files programmatically in your C# application. Remember to consult the IronPDF documentation and the examples provided by the library to explore the various features and capabilities it offers.

Converting PDF Files to Images with IronPDF

When working with PDF files in C#, IronPDF provides a convenient solution for converting these files to images. In this article, we will explore the capabilities of IronPDF and demonstrate how to convert PDF files to images using different approaches.

Loading a PDF File

To begin, we need to load a PDF file into our project. IronPDF offers a straightforward method called FromFile in the PdfDocument class to accomplish this task. The following code sample illustrates how to open an existing PDF file for editing:

PdfDocument pdf = PdfDocument.FromFile("Example.pdf");
PdfDocument pdf = PdfDocument.FromFile("Example.pdf");
Dim pdf As PdfDocument = PdfDocument.FromFile("Example.pdf")
VB   C#

Convert PDF file to Images

Once the PDF file is loaded, IronPDF provides the RasterizeToImageFiles method to convert PDF pages to image format. With a single line of code, we can convert the entire PDF document to JPG images:

VB   C#

The converted files will be saved in the specified path. IronPDF efficiently converts all the pages of the PDF document to JPG images. The method RasterizeToImageFiles handles the conversion process, automatically assigning incremental numerical names to the images.

How to Convert PDF to PNG in C#: Figure 4 - How to Convert PDF to JPG in .NET: Figure 2

Converting Specific PDF Pages

The RasterizeToImageFiles method also allows for more control over PDF to JPG conversion. You can also convert a particular page from a PDF document to image. The following code sample shows how to convert PDF pages in a specific range, from page 1 to 10:

IEnumerable<int> pageIndexes = Enumerable.Range(0, 10);
pdf.RasterizeToImageFiles(@"C:\image\folder\example_pdf_image_*.jpg", pageIndexes, 850, 650, IronPdf.Imaging.ImageType.Default, 300);
IEnumerable<int> pageIndexes = Enumerable.Range(0, 10);
pdf.RasterizeToImageFiles(@"C:\image\folder\example_pdf_image_*.jpg", pageIndexes, 850, 650, IronPdf.Imaging.ImageType.Default, 300);
Dim pageIndexes As IEnumerable(Of Integer) = Enumerable.Range(0, 10)
pdf.RasterizeToImageFiles("C:\image\folder\example_pdf_image_*.jpg", pageIndexes, 850, 650, IronPdf.Imaging.ImageType.Default, 300)
VB   C#

How to Convert PDF to PNG in C#: Figure 5

In this example, several parameters are specified:

  • First Parameter: A valid path with an optional image extension is provided as a string.
  • Second Parameter: pageIndexes indicates the page range to be converted to JPG images programmatically.
  • Third Parameter: The maximum image width in pixels is set.
  • Fourth Parameter: The maximum image height in pixels is specified.
  • Fifth Parameter: The image type is set to default, which will save images in PNG image format if the extension is not explicitly mentioned in the path. Other available formats include PNG, GIF, TIFF, JPG, and Bitmap.
  • Sixth Parameter: The desired resolution of the output image files can be set. Note that DPI will be ignored in Linux and macOS.

Converting URL to PDF and then PDF to Images

IronPDF also offers the ability to convert a URL to PDF and subsequently save each page of the generated PDF as a separate image file. This is particularly useful when capturing products or web page content as images. The following code snippet demonstrates this process by rendering an Amazon website page to a pixel-perfect PDF and then converting each page to a separate JPG file:

using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderUrlAsPdf("");
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderUrlAsPdf("");
Imports IronPdf

Private renderer As New ChromePdfRenderer()
Private pdf As PdfDocument = renderer.RenderUrlAsPdf("")
VB   C#

How to Convert PDF to PNG in C#: Figure 6 - How to Convert PDF to JPG in .NET: Figure 4

In this example, the ChromePdfRenderer class is used to render the URL as a PDF. Subsequently, the RasterizeToImageFiles method is called to convert each page of the generated PDF to a separate JPG file.

IronPDF, with its powerful capabilities and easy-to-use API, provides a comprehensive solution for converting PDF files to images programmatically in C#. By incorporating IronPDF into your projects, you can effortlessly handle PDF to image conversions, extract images, and manipulate PDF documents.


In this article, we have explored how to utilize IronPDF for .NET Framework to convert PDF documents into JPG image file format. The RasterizeToImageFiles method, as demonstrated in the code examples above, generates images that incorporate the document name and page number. With IronPDF, you can convert PDF pages into various image formats, including PNG, JPG, GIF, and more.

The IronPDF Library grants users complete control over the output image format, dimensions, and resolution. Additionally, IronPDF offers an array of other PDF manipulation tools such as page rotation, text modification, margin adjustment, and more. To delve deeper into the capabilities of IronPDF for .NET and access additional features for PDF file manipulation, please refer to the following here.

While IronPDF .NET Library is free for development purposes, it requires licensing for commercial usage. You can download the zip file for the IronPDF .NET library from this link and give it a try.

How to Display PDF Embedded Text in .NET MAUI
PDF vs PDFA (How It Works For Developers)

Ready to get started? Version: 2024.5 just released

Start Free Trial Total downloads: 9,229,207
View Licenses >