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
- Convert Excel to PDF using Java programmatically
- Excel to PDF conversion API - Advance options
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:
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://repository.aspose.com/repo/</url> </repository>
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-cells</artifactId> <version>22.6</version> </dependency>
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:
- Create a Workbook object and initialize it with a source Excel file.
- Access the first worksheet by getWorksheets().get(0) method.
- Instantiate an instance of PdfSaveOptions class to access the options for saving a pdf file.
- Invoke the setCompliance method to set its compliance to PDFA-1a.
- Access cell B8 by calling the getCells() method.
- Invoke the putValue method to insert some value in the B8 cell.
- Search & replace string by calling replace method.
- 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 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.
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, conholdate.com 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.