How to Convert Excel Spreadsheet to PDF Automatically with Java
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:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Next, add the below reference to the pom.xml dependency:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>
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)
//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.convertDocumentXlsxToPdf(inputFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDocumentApi#convertDocumentXlsxToPdf");
e.printStackTrace();
}
And that’s it — you’re all done. To get your API key, visit our website to register a free account.