Convert Office Word Documents (DOCX) to Text in C#

Basic document conversion tasks are easily achievable via the Cloudmersive API Console. With one API key, you can take advantage of dozens of useful document conversion APIs with code available in 13 different programming languages. Below, we’ll walk through connecting with the /convert/doc/to/txt iteration of the Convert API in C#.

Run the below command to install the .NET SDK:

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

After that, you can include the function below to call the API & copy in your API key where indicated. If you don’t currently have an API key, visit the Cloudmersive website to easily create a free account and you’ll receive a key once that process is complete.

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 );
}
}
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

436 Followers

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