How to Convert Excel Spreadsheet to PDF Automatically with Java

1 min readJun 9, 2022


If you’re trying to convert dozens of Excel Spreadsheets to PDF, it doesn’t make sense to open them all individually and select built-in conversion options. That’s a big waste of time, and there are much easier ways to do it. With the help of our Excel to PDF conversion API, you can automatically convert all worksheets in your Excel workbooks to PDF (both XLSX and XLSB formats are accepted). Below, we’ve provided complementary code in Java to help you structure your API call.

To start, add the below reference to the pom.xml repository to begin installing the Java SDK with Maven:


Next, add the below reference to the pom.xml dependency:


Now, one last step — copy in the import classes, then the rest of the callback function:

// 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.convertDocumentXlsxToPdf(inputFile);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDocumentApi#convertDocumentXlsxToPdf");

And that’s it — you’re all done. To get your API key, visit our website to register a free account.




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