How to Rasterize a PDF to Images

by Chaknith Bin

Rasterizing a PDF file involves converting it into a pixel-based image format like JPEG or PNG. This process transforms each page of the PDF into a static image, where the content is represented by pixels. Rasterization offers several advantages, including the ability to display PDF content, generate thumbnails, perform image processing, and facilitate secure document sharing.

With IronPDF, you can easily and programmatically convert PDFs to images. Whether you need to incorporate PDF rendering into your application, generate image previews, perform image-based operations, or enhance document security, IronPDF has you covered.


C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

Check out IronPDF on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming PDF with C#.

C# NuGet Library for PDF nuget.org/packages/IronPdf/
Install-Package IronPdf

Consider installing the IronPDF DLL directly. Download and manually install it for your project or GAC form: IronPdf.zip

Manually install into your project

Download DLL

Rasterize a PDF to Images Example

The RasterizeToImageFiles method is utilized to export images from a PDF document. This method is available on the PdfDocument object, whether you are importing a PDF document file locally or rendering it from an HTML file, HTML string, or web URL.

Please note
A file extension such as .png, .jpg, or .tif is required for the FileNamePattern parameter.

Tips
The asterisk (*) character contained in the FileNamePattern will be substituted with the corresponding page numbers.

:path=/static-assets/pdf/content-code-examples/how-to/rasterize-pdf-to-images-rasterize.cs
using IronPdf;

// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render PDF from web URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

// Export images from PDF
pdf.RasterizeToImageFiles("wikipage_*.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Output Folder

Output folder

If the form fields' values are intended to be visible in the output images, please flatten the PDF before converting it to an image or pass true to the Flatten parameter of the method. Forms will not be detectable after using the Flatten method.

Learn how to fill and edit PDF forms programmatically in the following article: "How to Fill and Edit PDF Forms."


Rasterize a PDF to Images Advance Example

Let's explore the additional parameters available for the RasterizeToImageFiles method.

Specify image type

Another parameter provided by the method allows you to specify the file types for the output images. We support BMP, JPEG, PNG, GIF, TIFF, and SVG formats. Each type has its corresponding method that can be directly invoked from the PdfDocument object to export the respective image type. Here are the available methods:

  • ToBitmap: Rasterizes (renders) the PDF into individual IronSoftware.Drawing.AnyBitmap objects, with one Bitmap for each page.
  • ToJpegImages: Renders the PDF pages as JPEG files and saves them to disk.
  • ToPngImages: Renders the PDF pages as PNG (Portable Network Graphic) files and saves them to disk.
  • ToTiffImages: Renders the PDF pages as single-page TIFF (Tagged Image File Format / Tif) files and saves them to disk.
  • ToMultiPageTiffImage: Renders the PDF pages as a single multipage TIFF file and saves it to disk.
  • SaveAsSvg: Converts the PDF document to an SVG format and saves it to the specified file path.
  • ToSvgString: Converts a specific page of the PDF document to an SVG format and returns it as a string.
:path=/static-assets/pdf/content-code-examples/how-to/rasterize-pdf-to-images-image-type.cs
using IronPdf;

// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render PDF from web URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

// Export images from PDF
pdf.RasterizeToImageFiles("wikipage_*.png", IronPdf.Imaging.ImageType.Png);
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Specify DPI

When using the default DPI of 96, the output images may appear blurry. To mitigate this phenomenon, it is important to specify a higher DPI value.

:path=/static-assets/pdf/content-code-examples/how-to/rasterize-pdf-to-images-dpi.cs
using IronPdf;

// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render PDF from web URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

// Export images from PDF with DPI 150
pdf.RasterizeToImageFiles("wikipage_*.png", DPI: 150);
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Specify pages index

It is also possible to specify the pages of the PDF document that you want to rasterize into image(s). In the example below, images of PDF document pages 1-3 will be generated as output.

:path=/static-assets/pdf/content-code-examples/how-to/rasterize-pdf-to-images-page-indexes.cs
using IronPdf;
using System.Linq;

// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render PDF from web URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

// Export images from PDF page 1_3
pdf.RasterizeToImageFiles("wikipage_*.png", Enumerable.Range(1, 3));
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Specify Image Dimensions

When converting PDF documents to images, you have the flexibility to customize the height and width of the output images. The provided height and width values represent the maximum dimensions, while ensuring that the aspect ratio of the original document is preserved. For instance, in the case of a portrait PDF document, the specified height value will be exact, while the width value may be adjusted to maintain the correct aspect ratio.

:path=/static-assets/pdf/content-code-examples/how-to/rasterize-pdf-to-images-image-dimensions.cs
using IronPdf;

// Instantiate Renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render PDF from web URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

// Export images from PDF
pdf.RasterizeToImageFiles("wikipage_*.png", 500, 500);
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Specifications for Output Images

The dimensions for the output images are specified using the width by height format, denoted as width x height.

Image rasterize from a portrait PDF
Image rasterize from a landscape PDF

Chaknith Bin

Software Engineer

Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.