PDF is a versatile format that is commonly used for printing and sharing documents. However, there could be cases when you need to convert PDF files to image formats programmatically. To accomplish that, this article covers how to convert PDF to JPG images in C# from within your .NET applications.
C# PDF to JPG Converter API – Free Download
Aspose.PDF for .NET is a powerful PDF manipulation API that lets you create and process PDF files from within your .NET applications. Furthermore, it allows you to convert PDF documents to other formats seamlessly. We will use this API to convert the pages from PDF documents to JPG format. You can either download the API or install it using NuGet.
PM> Install-Package Aspose.Pdf
PDF to JPG C# Conversion
The following are the steps to convert the pages in a PDF document to JPG images using Aspose.PDF for .NET.
- Load the PDF file using Document class.
- Loop through the pages of the PDF using Document.Pages collection.
- In each iteration, create a FileStream object for the output JPG image.
- Create and initialize an object of JpegDevice class.
- Convert page to JPG using JpegDevice.Process(Page, Stream) method.
The following code sample shows how to convert pages in PDF to JPG using C#.
Convert Single Page of PDF to JPG
You can also convert only a single page of PDF to JPG. In that case, you can access the desired page from Document.Pages collection. The following are the steps to convert only a single page of PDF to JPG.
- Load the PDF file using the Document class.
- Create FileStream for the output JPG image.
- Create and initialize the JpegDevice object.
- Convert page to JPG using JpegDevice.Process(Page, Stream) method.
The following code sample shows how to convert a single page in PDF to JPG.
Conclusion
In this post, you have learned how to convert pages in a PDF file to JPG images using C#. The code samples have shown how to convert all or desired pages of PDF to JPG images. In addition, you can explore more about .NET PDF API using the documentation. In case you would have any questions or queries, you can contact us via our forum.