How to Convert DOCX to JPG in C# .Net Framework
For anyone out there who has been struggling with converting your document files into images, this post is for you. Forget all those hundreds of lines of code that you thought you would need. Today we are going to get this done and over with after just two easy steps. Let’s dive straight in.
First we are going to open the package manager console and run this command. This will install our API client via NuGet:
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.2.8
And next we are going to call our function for converting DOCX to JPG:
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 ConvertDocumentDocxToJpgExample{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 Word DOCX Document to JPG/JPEG image arrayDocxToJpgResult result = apiInstance.ConvertDocumentDocxToJpg(inputFile, quality);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ConvertDocumentApi.ConvertDocumentDocxToJpg: " + e.Message );}}}}
And you are officially done! If you liked this simple approach, the rest of this library contains a great deal more API functions that cover everything from format conversion to editing and merging.