How to Convert DocX Files to JPG/JPEG Image Arrays using Java

2 min readJun 9, 2022


Converting Word Documents to Image Arrays is a great way to make the contents of those documents readable across any operating system. If you’re looking to make that conversion to JPG, we can help: our DocX to JPG Conversion API will make it possible to build that operation into your application and customize the output image quality. To help you structure your API call, we’ve provided instructions to use complementary, ready-to-run code in Java below.

Let’s begin by installing the Java SDK. To do so with Maven, first add a reference to the repository in pom.xml:


Then, add a reference to the dependency in pom.xml:


Lastly, it’s time to include the import classes and call the API:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.ConvertDocumentApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
ConvertDocumentApi apiInstance = new ConvertDocumentApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
Integer quality = 56; // Integer | 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.
try {
DocxToJpgResult result = apiInstance.convertDocumentDocxToJpg(inputFile, quality);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDocumentApi#convertDocumentDocxToJpg");

Make sure to include your Cloudmersive API key where indicated in the documentation, and you’re all set. To get a key, head to our website and register a free account.




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

Recommended from Medium