How to Rasterize a PDF & Convert to Word DOCX using C# .NET Framework

Cloudmersive
2 min readFeb 2, 2024

--

Converting rasterized PDFs to Word helps us avoid vector graphic elements in our resulting document. Writing code to rasterize AND convert PDFs to DOCX format in C# can be a little tricky — but thankfully we don’t have to do all that work on our own.

Using the code provided below, we can take advantage of a free API that first rasterizes a PDF document and then converts the document (at high fidelity) to DOCX format. To authorize our API calls, we’ll just need a free API key, which will allow us to make up to 800 API calls per month with no commitments (once we reach that limit, our total will reset the following month).

Let’s get started by installing the SDK. We can install via NuGet by running the following command in our Package Manager console:

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

Next, let’s 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 ConvertDocumentPdfToDocxRasterizeExample
{
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 Word DOCX Document based on rasterized version of the PDF
byte[] result = apiInstance.ConvertDocumentPdfToDocxRasterize(inputFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentPdfToDocxRasterize: " + e.Message );
}
}
}
}

Once we load our file & copy our API key into the correct snippet, we’re good to go. It’s just that easy — no more code required!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet