How to Convert PDF to PNG in C# .NET Framework

Cloudmersive
2 min readJan 12, 2024

--

Simple file format conversions often require an unreasonable amount of code. Thankfully, with a free low-code API solution, we can make simple conversions much more accessible.

Using the ready-to-run code examples below, we can easily convert multi-page PDF files to PNG image arrays. Much like PDFs, PNG files are lightweight and extremely interoperable, and they also support transparency features which can be useful for graphics and similar forms of content.

To take advantage of this API, we’ll need to start by installing the .NET SDK. We can do that by running the following command:

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.4.2

Next, we can get ready to authorize our API call by retrieving a free-tier API key. These allow a limit of 800 API calls per month with no additional commitments.

Finally, we can copy the below code into our file to call the function:

using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;

namespace Example
{
public class ConvertDocumentPdfToPngArrayExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");

var apiInstance = new ConvertDocumentApi();
var inputFile = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Input file to perform the operation on.

try
{
// Convert PDF to PNG Image Array
PdfToPngResult result = apiInstance.ConvertDocumentPdfToPngArray(inputFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentPdfToPngArray: " + e.Message );
}
}
}
}

Now we’re all done — we can quickly and conveniently convert our PDF files to PNG arrays with minimal code.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet