How to Convert Word DocX to PDF With Java

2 min readJun 8, 2022


A lot of people use Microsoft Word as their default application for writing and editing plain text. However, if you don’t have MS applications installed on your computer, you probably know how annoying that proprietary format can be to open elsewhere. If your application is handling with high volumes of word document uploads, don’t waste time converting each one individually — take control of that process with our Word DocX to PDF conversion API. By utilizing simple, ready-to-run code examples we’ve provided below in Java, you can easily structure your API call in just a few seconds, and put your conversion needs to rest.

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


And then let’s add one to the dependency:


Now it’s time to finish up and complete the API call. Include the below code block to do so, starting with the import classes:

// 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.
try {
byte[] result = apiInstance.convertDocumentDocxToPdf(inputFile);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDocumentApi#convertDocumentDocxToPdf");

And just like that, you’re all done — no further coding required. You will, however, need an API key for access, and you can easily get one by registering a free account on our website.




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

Recommended from Medium