How to convert a PDF to PNG array using C# in .NET Framework

Cloudmersive
1 min readOct 2, 2019

--

While PDF format is generally pretty robust, it can be a bit unwieldy. Sometimes a PNG array works much better, allowing easier web display and image editing. Let’s look at an easy way to accomplish this.

First, install the API client that we will need by running the following command in your Package Manage console:

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

Second, we simply call ConvertDocumentPdfToPngArray:

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");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");
var apiInstance = new ConvertDocumentApi();
var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.
try
{
// PDF to PNG Array
PdfToPngResult result = apiInstance.ConvertDocumentPdfToPngArray(inputFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentPdfToPngArray: " + e.Message );
}
}
}
}

All done! Your return will be a JSON file that contains a URL for each PNG file, making it a simple task to download them.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet