How to Convert RTF to PDF in C# .NET Framework

Cloudmersive
2 min readJan 31, 2024

--

It might be easier to create written content in RTF format, but when it comes to publishing & sharing that content, PDF remains the best option. It can be difficult to carry out this conversion in C# — so it might be easier to lean on a low-code API solution.

Using the below code, we can take advantage of a free API to convert our RTF documents to PDF format. All we need to do is load our file in for a multipart/form-data req uest, and we’ll receive the file encoding string for our new PDF document in return.

Before we get started with code examples, we’ll first need to grab a free-tier API key to authorize our requests. These allow a limit of 800 API calls per month with no additional commitments; our total will simply reset once we reach it.

With our API key ready, let’s go ahead and install the SDK. We can run the following command in our Package Manager console to install via NuGet:

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

Next, let’s call the function. We can copy the below code to do so (let’s make sure we enter our API key and file data in the appropriate parameters):

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 ConvertDocumentRtfToPdfExample
{
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 Rich Text Format RTF to PDF
byte[] result = apiInstance.ConvertDocumentRtfToPdf(inputFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentRtfToPdf: " + e.Message );
}
}
}
}

Now we can make quick, easy & free API requests to handle a useful document conversion workflow.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet