Friday, 21 May 2021

Convert PDF to Excel using a free API

This article will introduce how to convert PDF to Excel using a free API called Free Spire.PDF for Java. Actually, I used the API to convert PDF to Image/Word previously, and to be honestly, it is the best one I have used so far because demos it provided are simple to know and the resulting documents can meet my requirements after running relevant codes.

You can download the product package from E-icblue official website, unzip it and get Spire.Pdf.jar in the “lib” folder, then add the jar file to IDEA. Of course, you can directly refer to it by using the following Maven configuration.

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf.free</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>

Using the code

The following is my PDF document including a table, and now I want to convert it to Excel.


import com.spire.pdf.*;

public class ConvertPDFToXLS {
public static void main(String[] args) {
//Create PDF document
PdfDocument pdf = new PdfDocument();
//Load the PDF document from disk.
pdf.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pdf");
//Save the document
pdf.saveToFile("output/pdfToExcel.xlsx", FileFormat.XLSX);
}
}

Output



No comments:

Post a Comment

Change PDF Versions in Java

In daily work, you might need to change the version of a PDF document you have in order to ensure compatibility with another version which a...