Saltar al pie de página
USANDO IRONPDF

Cómo Convertir PDF a JPG en .NET

This tutorial will use IronPDF for C# .NET to convert PDF to JPG images.

IronPDF - .NET Library

IronPDF for .NET is a library that allows users to create, edit, and manage PDF files. It is very popular among C# developers because of its PDF generation component, which allows them to work with PDF files without Adobe Acrobat installed. IronPDF for .NET allows conversion between different formats like HTML to PDF, URL to PDF, and Images to PDF.

It also supports adding custom headers & footers, digital signatures, annotations, and attachments, user and owner passwords, and other security options. IronPDF has a fast Chromium Engine for a better rendering experience. It renders a pixel-perfect PDF. It also provides full multithreading and async support.

Now, the next section will discuss how to convert PDF format to image formats like PNG or JPG programmatically using IronPDF.

Prerequisites

Before starting, Visual Studio's latest version is recommended to be downloaded from the official Visual Studio website and installed. This is necessary for building C# apps, helping set up the .NET environment, and preparing to make a PDF to JPG converter.

IronPDF Installation

To install IronPDF, there are multiple ways:

  1. You can download IronPDF using the NuGet Package Manager into your C# project created using Visual Studio. Access NuGet Package Manager via Tools or by right-clicking Solution Explorer. Browse for the IronPDF package and install it.
  2. Another way to install IronPDF is by directly downloading it from the NuGet IronPDF page.

Convert PDF File to Images using IronPDF

Load PDF Document

To load a PDF file from a local location into this project, IronPDF provides a FromFile method present in the PdfDocument class. The following code example helps to open an existing PDF file for editing:

using IronPdf;

// Load the PDF document from a local path
PdfDocument pdf = PdfDocument.FromFile("Example.pdf");
using IronPdf;

// Load the PDF document from a local path
PdfDocument pdf = PdfDocument.FromFile("Example.pdf");
Imports IronPdf

' Load the PDF document from a local path
Private pdf As PdfDocument = PdfDocument.FromFile("Example.pdf")
$vbLabelText   $csharpLabel

Convert PDF Documents to Images

Now, the file is opened for editing. IronPDF provides a RasterizeToImageFiles method to convert PDF pages to Image format. With the following one line of code, it is very easy to convert the entire PDF document into JPG images using IronPDF's Rasterize Method.

// Convert all pages of the PDF into JPG images and save them to the specified folder
pdf.RasterizeToImageFiles(@"C:\image\folder\*.jpg");
// Convert all pages of the PDF into JPG images and save them to the specified folder
pdf.RasterizeToImageFiles(@"C:\image\folder\*.jpg");
' Convert all pages of the PDF into JPG images and save them to the specified folder
pdf.RasterizeToImageFiles("C:\image\folder\*.jpg")
$vbLabelText   $csharpLabel

The converted files from the above code will be saved in the given path. The PDF contains 562 pages, and IronPDF takes no time to convert all PDF pages to JPG images. The RasterizeToImageFiles method does all the hard work, and the name of images is a digit that starts from 1 and is incremented by each page.

How to Convert PDF to JPG in .NET, Figure 2: The images extracted from the PDF file The images extracted from the PDF file

Convert Specific PDF Pages

The RasterizeToImageFiles method provides other options too for more control over PDF Pages to JPG conversion. The following code helps to convert PDF pages in a range from page 11 to 21.

using System.Collections.Generic;
using System.Linq;

// Set the Page Range
IEnumerable<int> pageIndexes = Enumerable.Range(10, 11); // Corrected range to cover pages 11 to 21

// Path, PageIndexes, ImageType and Dimensions may be specified
pdf.RasterizeToImageFiles(@"C:\image\folder\example_pdf_image_*.jpg", pageIndexes, 850, 650, IronPdf.Imaging.ImageType.Default, 300);
using System.Collections.Generic;
using System.Linq;

// Set the Page Range
IEnumerable<int> pageIndexes = Enumerable.Range(10, 11); // Corrected range to cover pages 11 to 21

// Path, PageIndexes, ImageType and Dimensions may be specified
pdf.RasterizeToImageFiles(@"C:\image\folder\example_pdf_image_*.jpg", pageIndexes, 850, 650, IronPdf.Imaging.ImageType.Default, 300);
Imports System.Collections.Generic
Imports System.Linq

' Set the Page Range
Private pageIndexes As IEnumerable(Of Integer) = Enumerable.Range(10, 11) ' Corrected range to cover pages 11 to 21

' Path, PageIndexes, ImageType and Dimensions may be specified
pdf.RasterizeToImageFiles("C:\image\folder\example_pdf_image_*.jpg", pageIndexes, 850, 650, IronPdf.Imaging.ImageType.Default, 300)
$vbLabelText   $csharpLabel

In the above convert a range of PDF pages to JPG example using IronPDF, a lot of things are happening. Let's have a look at them one by one.

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

The JPG conversion output will be:

How to Convert PDF to JPG in .NET, Figure 2: The images extracted with more control The images extracted with more control

Convert URL to PDF and then PDF to Images

Sometimes there is a need to capture the products listed on a website as images for some purpose. Let's say there are hundreds of products listed on a website page. Taking screenshots will be a time-consuming and hectic task. IronPDF provides the facility to convert a URL to PDF and use the generated PDF document to save each page to an image.

The following code takes the Amazon website page as a URL and renders it to a pixel-perfect PDF. After that, each page of the generated PDF is converted to a separate JPG file.

using IronPdf;

// Create a PDF renderer using the Chromium rendering engine
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render the URL to a PDF document
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.amazon.com/?tag=hp2-brobookmark-us-20");

// Convert each page of the PDF to separate JPG image files
pdf.RasterizeToImageFiles(@"C:\image\folder\amazon_pdf_image_*.jpg");
using IronPdf;

// Create a PDF renderer using the Chromium rendering engine
ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render the URL to a PDF document
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.amazon.com/?tag=hp2-brobookmark-us-20");

// Convert each page of the PDF to separate JPG image files
pdf.RasterizeToImageFiles(@"C:\image\folder\amazon_pdf_image_*.jpg");
Imports IronPdf

' Create a PDF renderer using the Chromium rendering engine
Private renderer As New ChromePdfRenderer()

' Render the URL to a PDF document
Private pdf As PdfDocument = renderer.RenderUrlAsPdf("https://www.amazon.com/?tag=hp2-brobookmark-us-20")

' Convert each page of the PDF to separate JPG image files
pdf.RasterizeToImageFiles("C:\image\folder\amazon_pdf_image_*.jpg")
$vbLabelText   $csharpLabel

How to Convert PDF to JPG in .NET, Figure 3: Extracted images from an Amazon website Extracted images from an Amazon website

Conclusion

This article demonstrated how to convert PDF documents to JPG images using IronPDF for the .NET Framework. The RasterizeToImageFiles method produces images that contain the page number along with the document name, as shown in the above code examples. IronPDF can convert PDF pages into images in different formats: PNG, JPG, GIF, and many more.

The IronPDF Library provides full control over the output image format, dimensions, and resolution to its users. IronPDF also provides other PDF tools such as rotating PDF pages, changing PDF text, setting margins, etc. To learn more about IronPDF for .NET and to access additional features to manipulate PDF files, please refer to the following IronPDF examples for PDF manipulation. For more information on how to convert PDF to different format images, visit these code samples for IronPDF JPG conversion.

The IronPDF .NET Library is free for development but needs to be licensed for commercial use at Iron Software Licensing Page.

Download the IronPDF for .NET Library Zip File and give it a try.

Preguntas Frecuentes

¿Cómo puedo convertir un PDF a JPG en .NET?

Puede usar el método RasterizeToImageFiles de IronPDF para convertir páginas PDF en imágenes JPG. Este método proporciona control sobre el formato de la imagen de salida, las dimensiones y la resolución.

¿Puedo convertir páginas específicas de un PDF a JPG usando IronPDF?

Sí, IronPDF le permite convertir páginas específicas de un PDF a JPG especificando el rango de páginas en el método RasterizeToImageFiles.

¿Cómo instalo IronPDF en un proyecto .NET?

IronPDF se puede instalar usando el Administrador de Paquetes NuGet en Visual Studio. Puede buscar IronPDF en el administrador de paquetes y agregarlo a su proyecto.

¿Es posible convertir una URL a PDF antes de convertir a imágenes JPG?

Sí, IronPDF puede convertir una URL a un PDF utilizando su motor de renderizado Chromium y luego convertir el PDF resultante a imágenes JPG.

¿Cuáles son los formatos de imagen compatibles con IronPDF para la conversión de PDF?

IronPDF admite la conversión de páginas PDF en varios formatos de imagen, incluidos JPG, PNG, GIF, TIFF y Bitmap.

¿IronPDF requiere una licencia para uso comercial?

IronPDF es gratuito para propósitos de desarrollo, pero se requiere una licencia para uso comercial. Los detalles de la licencia están disponibles en la Página de Licencias de Iron Software.

¿Puede usarse IronPDF en sistemas operativos distintos de Windows?

IronPDF está diseñado principalmente para entornos Windows, pero también puede usarse en Linux y macOS, aunque algunas funciones como los ajustes de DPI pueden no estar totalmente soportadas.

¿Cuáles son algunas de las características avanzadas de IronPDF?

IronPDF ofrece características avanzadas como la adición de encabezados y pies de página personalizados, firmas digitales, anotaciones y adjuntos. También admite operaciones de multiproceso y asíncronas para un rendimiento mejorado.

¿IronPDF es compatible con .NET 10 al convertir archivos PDF a imágenes JPG?

Sí, IronPDF es totalmente compatible con .NET 10, incluidos sus métodos de PDF a imagen como RasterizeToImageFiles , por lo que puede convertir páginas PDF a imágenes JPG en proyectos .NET 10 sin problemas de compatibilidad.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más