How to Convert RTF to JPG in C# .Net Framework
If you are struggling with performing conversions between document and image formats, you are definitely not alone. The process is time consuming, tedious, and has numerous steps that all need to work in concert. Setting this up properly in code can take an entire day, or even longer. To alleviate this, today’s post is all about how to set this up with minimal effort.
First up, we need to install our API client, which can be accomplished using the following command for the NuGet console.
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.2.8
And now we can go ahead with our function call, which is going to look a little something like this here:
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 ConvertDocumentRtfToJpgExample{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.var quality = 56; // int? | Optional; Set the JPEG quality level; lowest quality is 1 (highest compression), highest quality (lowest compression) is 100; recommended value is 75. Default value is 75. (optional)try{// Convert Rich Text Format RTF to JPG/JPEG image arrayRtfToJpgResult result = apiInstance.ConvertDocumentRtfToJpg(inputFile, quality);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentRtfToJpg: " + e.Message );}}}}
Now just enter your input file and your desired JPG quality level. That’s it!