Occasionally, you might be in a sitution where you need to extract table from a PDF document and save the table date either in a Word file or in an Excel worksheet, so that you can edit the date freely. In this article, I am going to show you how to convert a whole PDF document to Excel or Word by using Spire.PDF for Java.
Below is a screenshot of the input file.
Install Spire.Pdf.jar
If you’re creating a Maven project, you can easily add the jar in your applciation using the following configurations. For non-Maven projects, download the jar file from this link and add it as a dependency in your applicaiton.
<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</artifactId>
<version>3.8.5</version>
</dependency>
</dependencies>
Convert PDF to Excel (XLS/XLSX)
public class ConvertPdfToExcel {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load a PDF file
pdf.loadFromFile("C:\\Users\\Administrator\\Desktop\\table.pdf");
//Save as Excel file
pdf.saveToFile("ToExcel.xlsx", FileForma.XLSX);
}
}
Convert PDF to Word (DOC/DOCX)
public class ConvertPdfToWord {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load a PDF file
pdf.loadFromFile("C:\\Users\\Administrator\\Desktop\\table.pdf");
//Save as Word file
pdf.saveToFile("ToWord.docx", FileFormat.DOCX);
}
}
Top comments (0)