Are you looking for a high-speed, high-quality, and easy-to-implement PDF to PNG conversion solution in C#? If yes, this article provides a quick, powerful, and high-fidelity method of converting PDF files to PNG images in C#. The step-by-step guide shows how to implement PDF to PNG conversion within a few simple steps.
C# Library to Convert PDF to PNG
To convert PDF files to PNG images, we will use Aspose.PDF for .NET. It is a powerful PDF manipulation library that lets you process and convert PDF files from within your .NET applications. You can either download the library or install it using NuGet.
PM> Install-Package Aspose.PDF
TIP: Other Aspose products (Aspose.Slides for .NET, for example) also allow you to convert PDF to PNG using C# code. You can also use it convert PDF to XML, convert PDF to JPG, convert PDF to SVG, and also convert PDF to other images. You may also use it to convert PDF documents to non-image formats like HTML and import PDF from JPG, get it from PNG, and from other images.
How to Convert PDF to PNG in C#
The following are the steps to convert the pages in a PDF to PNG 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 PNG image.
- Create and initialize an object of PngDevice object.
- Convert page to PNG using PngDevice.Process(Page, Stream) method.
The following code sample shows how to convert a PDF to PNG in C#.
C# Convert a Page of PDF to PNG
You can also convert only a single page of PDF to PNG. 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 PNG.
- Load the PDF file using Document class.
- Create FileStream for the output PNG image.
- Create and initialize the PngDevice object.
- Convert page to PNG using PngDevice.Process(Page, Stream).
The following code sample shows how to convert a page in PDF to PNG in C#.
Free PDF to PNG Conversion
You can get a free temporary license and convert PDF to PNG images without any limitations.
Explore C# PDF to PNG Converter
You can explore more about C# PDF to PNG converter library using the documentation.
Conclusion
In this post, you have learned how to convert pages in a PDF file to PNG images using C#. The code samples have shown how to convert all or desired pages of PDF to PNG images.