Cómo rasterizar un PDF a una imagen

How to Rasterize a PDF to Images

This article was translated from English: Does it need improvement?
Translated
View the article in English

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.

Quickstart: Effortless PDF Rasterization in .NET with IronPDF

Easily convert PDF pages to images using IronPDF's simple API. This quickstart guide demonstrates how to load a PDF and export each page as an image file, allowing you to seamlessly integrate rasterization capabilities into your .NET applications. Perfect for generating thumbnails, enhancing document security, or preparing files for further processing, this approach ensures a smooth and efficient workflow.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    IronPdf.PdfDocument.FromFile("input.pdf").RasterizeToImageFiles("page_*.png");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer


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 to PDF conversion guide, HTML string to PDF conversion guide, or URL to PDF conversion guide.

Por favor notaA file extension such as .png, .jpg, or .tif is required for the FileNamePattern parameter.

ConsejosThe 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
$vbLabelText   $csharpLabel

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 to High Quality Bitmap

For users who want to retain the original resolution of their images when converting to a Bitmap, please use ToBitmapHighQuality instead of ToBitmap. The ToBitmap method returns an image decoded from JPEG, while the ToBitmapHighQuality method returns an image decoded from the BMP format. The BMP format stores the raw data of each pixel, which results in a sharper image but also a very large file size. In contrast, JPEG uses a lossy compression algorithm, which significantly reduces file size at the cost of a slightly blurrier image. For most use cases, such as printing and viewing PDFs, the image quality from JPEG is sufficient.

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

PdfDocument pdf = PdfDocument.FromFile("url.pdf");

var image = pdf.ToBitmapHighQuality();
image[0].SaveAs("output.png");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Rasterize a PDF to Images Advanced 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. Here are the available methods:

  • ToBitmap: Rasterizes (renders) the PDF into individual 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 files and saves them to disk.
  • ToMultiPageTiffImage: Renders the PDF pages as a single multi-page 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

Specify DPI

When using the default DPI of 96, the output images may appear blurry. To improve clarity, it is important to specify a higher DPI value when rasterizing.

: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
$vbLabelText   $csharpLabel

Specify Pages Index

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

: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
$vbLabelText   $csharpLabel

Specify Image Dimensions

When converting PDF documents to images, you have the flexibility to customize the height and width of the output images. The specified 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
$vbLabelText   $csharpLabel

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

Preguntas Frecuentes

¿Cuál es el proceso de rasterizar un PDF?

Rasterizar un PDF implica convertir cada página del documento PDF en un formato de imagen basado en píxeles, como JPEG o PNG, usando herramientas de software como IronPDF.

¿Por qué es útil rasterizar PDFs?

Rasterizar PDFs es útil para mostrar contenido como imágenes, generar miniaturas, realizar procesamiento de imágenes y mejorar la seguridad del documento al evitar la extracción de texto.

¿Cómo puedo convertir un PDF a formatos de imagen usando C#?

Puedes usar el método RasterizeToImageFiles de IronPDF en C# para convertir documentos PDF en formatos de imagen como BMP, JPEG, PNG, GIF, TIFF y SVG de manera programática.

¿A qué formatos de archivo de imagen se pueden convertir los PDFs?

Usando herramientas como IronPDF, los PDFs pueden rasterizarse en varios formatos de imagen, incluidos BMP, JPEG, PNG, GIF, TIFF y SVG.

¿Cómo ajusto el DPI para obtener imágenes más claras al rasterizar PDFs?

Puedes especificar el DPI deseado al usar IronPDF para rasterizar PDFs, lo que te permite controlar la claridad y resolución de las imágenes de salida.

¿Se pueden rasterizar páginas específicas de un PDF a imágenes?

Sí, IronPDF te permite especificar páginas particulares de un documento PDF para la rasterización a imágenes definiendo los índices de página en el método de conversión.

¿Cómo puedo cambiar las dimensiones de las imágenes de salida de una conversión de PDF?

Al convertir PDFs a imágenes usando IronPDF, puedes personalizar las dimensiones de la imagen de salida configurando la altura y anchura máximas mientras mantienes la relación de aspecto.

¿Cuál es el método para asegurar que los campos de formulario sean visibles en las imágenes convertidas?

Para asegurar que los campos de formulario sean visibles en las imágenes de salida, debes aplanar el formulario PDF usando IronPDF antes de la conversión o habilitar la opción de aplanado en el método.

¿Cómo puedo guardar un PDF como un archivo TIFF de varias páginas?

Con IronPDF, puedes usar el método ToMultiPageTiffImage para convertir y guardar todas las páginas de un PDF como un solo archivo TIFF de varias páginas.

¿Es posible convertir un PDF a formato SVG?

Sí, IronPDF proporciona métodos como SaveAsSvg y ToSvgString para convertir documentos PDF en formato SVG.

¿IronPDF admite la rasterización de archivos PDF en proyectos .NET 10 de forma predeterminada?

Sí: IronPDF es totalmente compatible con .NET 10 y admite la rasterización de archivos PDF a imágenes cuando se utilizan en aplicaciones .NET 10 sin necesidad de soluciones especiales.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado