There could be various scenarios when you need to export the data within the tables from PDF to Excel workbooks. PDF to Excel lets you edit the data, apply formulas, plot charts, and perform other operations that are supported by the spreadsheets. In this article, I’ll show you how to automate the PDF to Excel conversion and convert PDF to XLS to XLSX workbooks programmatically using Java. For this, we’ll leverage the capabilities of Aspsoe.PDF for Java API.
- PDF to Excel Converter API – Installation
- Convert PDF to XLS using Java
- Convert PDF to XLSX using Java
- PDF to Excel – Minimize the Number of Worksheets
Java PDF to Excel Converter – Installation
Aspose.PDF for Java is available for download as a JAR file. In addition, you can install it in your Maven-based applications using the following configurations.
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>20.5</version>
<classifier>jdk17</classifier>
</dependency>
Convert PDF to Excel XLS using Java
In order to convert PDF to Excel XLS, you simply need to load the PDF document and save it with .xls extension. The following are the steps to perform this conversion.
- Load the PDF file using Document class.
- Save the PDF as Excel XLS using Document.save(String outputFileName, int format) method.
The following code sample shows how to convert PDF to Excel XLS using Java.
Input PDF Document
Output Excel Spreadsheet
Convert PDF to Excel XLSX using Java
For converting PDF to XLSX spreadsheet, you need to define the output Excel format using ExcelSaveOptions class. The following are the steps to perform PDF to XLSX conversion using Aspose.PDF for Java.
- Load the input PDF document using the Document class.
- Create an instance of ExcelSaveOptions class.
- Set the output format using ExcelSaveOptions.setFormat(ExcelSaveOptions.ExcelFormat.XLSX) method.
- Convert PDF to Excel using Document.save(String outputFileName, SaveOptions options) method.
The following code sample shows how to convert PDF to XLSX using Java.
Minimize the Number of Worksheets in PDF to Excel
By default, Aspose.PDF converts each page in the PDF document to a separate worksheet. However, you may customize the API to minimize the number of worksheets in case of large PDF documents. The following are the steps to perform this operation.
- Use the Document class to load the input PDF document.
- Create an instance of ExcelSaveOptions class.
- Set option ExcelSaveOptions.setMinimizeTheNumberOfWorksheets(true).
- Save PDF as XLSX.
The following code sample shows how to convert PDF to XLSX with a minimized number of worksheets using Java.
Conclusion
In this article, you have seen how to convert PDF to Excel XLS or XLSX files using Java. Furthermore, the feature of minimizing the number of worksheets in PDF to Excel is also discussed with the help of the code sample. You can explore more about Aspose.PDF for Java using the documentation.