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

Cloudmersive
1 min readFeb 22, 2022

--

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

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet