Convert Word DOCX Document to PDF in C#
1 min readFeb 22, 2022
Take advantage of simple, copy & paste code from the Cloudmersive API Console to harness one of the most in-demand document conversion operations out there. Check out how to connect in C# below.
First, install the .NET Framework SDK:
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.4.2
After that, copy & paste the rest of the callback function. Make sure to include your Cloudmersive API key within the snippet Configuration.Default.AddApiKey(“Apikey”, “YOUR_API_KEY”). If you don’t currently have a key, you can easily get one by making a free account on the Cloudmersive website.
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 ConvertDocumentDocxToPdfExample
{
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 Word DOCX Document to PDF
byte[] result = apiInstance.ConvertDocumentDocxToPdf(inputFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentDocxToPdf: " + e.Message );
}
}
}
}