Read this article if you are looking for an accurate, high-speed, and high-quality conversion of PDF files to Excel sheets in Java.
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 Excel XLS to XLSX programmatically in Java.
- 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
To convert PDF files to Excel sheets, we will use Aspose.PDF for Java. The library provides a free, powerful, and high-fidelity PDF to Excel converter. It 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>22.12</version>
<classifier>jdk17</classifier>
</dependency>
Convert PDF to Excel XLS in Java
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
Java PDF to Excel XLSX
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.
Free PDF to Excel Java Converter
You can get a free temporary license to convert PDF files to Excel format without evaluation limitations.
Explore PDF to Excel Conversion Library
In case you are interested in exploring other features of Aspose.PDF for Java, visit the documentation here.
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.