Do you need to render the pages in a PDF file to JPG images in C#? If yes, this article provides one of the best and easiest methods to convert pages in a PDF to JPG in C#. Not only this, the method ensures high-quality and speedy PDF to JPG conversion. Let’s go through a complete step-by-step guide on how to convert PDF to JPG in C#.
C# Library to Convert PDF to JPG
To convert PDF files to JPG images, we will use Aspose.PDF for .NET. It is a powerful PDF manipulation library 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.
You can either download the library or install it using NuGet.
PM> Install-Package Aspose.PDF
How to Convert PDF to JPG in C#
The following are the steps to convert the pages in a PDF to JPG images in C#.
- 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 a PDF to JPG using C#.
Convert a Page of PDF to JPG in C#
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.
Free C# PDF to JPG Conversion
You can get a free temporary license and convert as many PDF files to JPG as you want without any limitations.
Explore C# PDF to JPG Converter
You can explore more about the C# PDF library using the documentation. In case you would have any questions or queries, you can contact us via our forum.
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. You only need to install the library and you can carry out PDF to JPG conversion in your C# application.