How to Convert PDF to PNG in C#

How to Convert PDF to PNG in C#

There are many programmatic solutions available regarding the conversion of PDF documents to other popular image file formats such as JPG, PNG, SVG, and more. This blog post will install this rich-featured PDF conversion library in our existing .NET project. Doing so will teach us how to convert PDF to PNG in C# by writing a few lines of source code. Let’s start this tutorial and achieve our end goal in the shortest time.

We will cover the following points:

PDF to PNG Conversion C# library installation

This library offers a wide range of features to manipulate and process PDF documents programmatically. However, you may configure the library by downloading the DLL files or install it by running the following command in the NuGet package manager.

Install-Package Aspose.Words 

How to Convert PDF to PNG in C#

In this section, we will write the code snippets that automate the process of PDF to PNG conversion in a .NET application.

You can follow the following steps:

  1. Instantiate an instance of the Document class and load a source PDF file.
  2. Initialize an object of the ImageSaveOptions class and the format to JPEG.
  3. Set the value of the “PageSet” property to “0” to convert only the first page of a document.
  4. Change the image’s brightness by setting the value of ImageBrightness property.
  5. Set the contrast by setting the value of ImageContrast property.
  6. Change the horizontal resolution by setting the value of the HorizontalResolution property.
  7. Invoke the save method to save the file in PNG format.

Copy & paste the following code into your main file:

The output can be seen in the image below:

PDF to PNG converter C#

Get a Free License

You can get a free temporary license to try the API without evaluation limitations.

Summing up

To conclude, you have explored how to convert PDF to PNG in C# by going through the steps and the code snippet. In addition, this article could be helpful for you if you are looking to develop a PDF to PNG C# converter programmatically. Moreover, you can visit the documentation to learn other methods of this PDF conversion library.

Moreover, we suggest you follow our Getting Started guide.

Finally, conholdate.com is writing new blog posts. So, please stay in touch for regular updates.

Ask a question

You can let us know about your questions or queries on our forum.

FAQs

How do you change a PDF to a picture file?

Instantiate an instance of the Document class and load a source PDF file, invoke the save method to save the file in PNG format.

See Also