How to convert any Document Format into PDF in C# .NET Framework
1 min readJul 23, 2020
Today I have something special for you. It’s a method by which we can take a whole mess of differing file formats (even with mislabeled extensions) and converting it into a nice clean stack of PDFs. If you were to attempt this manually, you would be in for a real challenge, most likely requiring weeks to get up and running. In this tutorial, I will have you up and ready in minutes.
First we install our package using the NuGet console:
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.2.8
Next we can go ahead and call our function for autodetect to PDF:
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 ConvertDocumentAutodetectToPdfExample{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 ConvertDocumentApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Convert Document to PDFbyte[] result = apiInstance.ConvertDocumentAutodetectToPdf(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentAutodetectToPdf: " + e.Message );}}}}
And now just toss in your files and let it run. Easy.