How to Convert Excel XLS (97–03) Spreadsheets to PDF using Java

Cloudmersive
2 min readOct 11, 2022

--

If you’re saving & sharing older datasets for your current projects/presentations, you may have run into a few 97–03 Excel XLS documents along the way. These documents are stored in a different format than modern XLSX documents, which means they require a little extra handholding when transitioning into common destination formats like PDF. Thankfully, with the help of our Excel 97–03 to PDF Conversion API, you can easily transition these documents to PDF in a single step. The best part? You can do it for free by registering a free account on our website (this will provide an API key which is good for 800 uses per month; there are zero hidden financial commitments in this account). When your account is good to go, you can use the below code examples to structure your API call and authenticate your API key in the appropriate field.

Before we call the Document Conversion function, we first need to install the API client. Let’s begin by adding a reference to the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

And let’s wrap up installation by adding a final reference to the dependency in pom.xml:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

Now we can turn our attention to the controller. We’ll first need to include the imports at the top of our file, and then include the remaining code examples to call the function. Within this code, you can authenticate your API key & include your inputFile path in the appropriate fields (indicated by the code comments):

// 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)
//Apikey.setApiKeyPrefix("Token");
ConvertDocumentApi apiInstance = new ConvertDocumentApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
try {
byte[] result = apiInstance.convertDocumentXlsToPdf(inputFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDocumentApi#convertDocumentXlsToPdf");
e.printStackTrace();
}

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet