How to rasterize a PDF into an image-based PDF in C# .NET Framework
1 min readFeb 6, 2020
Rasterizing a PDF file is a bit tricky to accomplish using traditional coding means. Luckily for you, this post is actually about a shortcut method using an API instead.
Before we get started, we need to install our API client. This is done by running the following command in Package Manager’s console.
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0
Now we can use the following code to call the EditPdfRasterize 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 EditPdfRasterizeExample{public void main(){// Configure API key authorization: ApikeyConfiguration.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 EditPdfApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Rasterize a PDF to an image-based PDFbyte[] result = apiInstance.EditPdfRasterize(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditPdfApi.EditPdfRasterize: " + e.Message );}}}}
And… that’s it. We are seriously all done. If this was a helpful method for you, bear in mind that we have hundreds of similar functions available.