Convert Excel to PDF using Java

Convert Excel to PDF using Java

Load a source Excel file, manipulate it and convert it to PDF file format by using a few lines of source code. This Java library provides a huge stack of methods to make file conversion & manipulation tasks quick and efficient. In the recent past, we published an article that demonstrates how to convert Excel to PDF in the Node.js application. In this blog post, we will learn how to convert Excel to PDF using Java programmatically.

The following points will be covered:

Java Excel library installation

We are going to use Java Excel API that comes up with comprehensive documentation regarding usage. However, it is easy to integrate with Java applications.

You can either download the JAR files or follow the following Maven configurations:


    <name>Aspose Java API</name>



Convert Excel to PDF using Java programmatically

In this section, we will learn how to achieve the Excel to PDF conversion programmatically. It lets you perform various actions, you can track the conversion progress of huge files, and more.

We will cover the following steps and the code snippet:

  1. Create a Workbook object and initialize it with a source Excel file.
  2. Access the first worksheet by getWorksheets().get(0) method.
  3. Instantiate an instance of PdfSaveOptions class to access the options for saving a pdf file.
  4. Invoke the setCompliance method to set its compliance to PDFA-1a.
  5. Access cell B8 by calling the getCells() method.
  6. Invoke the putValue method to insert some value in the B8 cell.
  7. Search & replace string by calling replace method.
  8. Save the output pdf file by calling the save method.

The following image shows the output of the above code snippet:

Excel to PDF conversion

Excel to PDF conversion API - Advance options

In the previous section, we have gone through the code snippet to convert MS Excel file to PDF file programmatically. We also have implemented some other methods such as searching & replace text and adding text into the file. However, you can explore the documentation of this Java Excel API to know about the other features.

Get a Free License

You can avail a free temporary license to try the API without evaluation limitations.

Summing up

We are ending this blog post here. We do hope you have learned how to convert Excel to PDF using Java programmatically. In addition, this library lets you do more than file conversion. However, this article will help you if you are looking to use Excel to PDF conversion API for your Java application. There are other relevant articles mentioned in the “See Also” section below. Finally, is in a consistent process of writing new blog posts. Therefore, stay connected for the latest updates.

Ask a question

You can let us know about your questions or queries on our forum.

See Also