DEV Community

E-iceblue Product Family
E-iceblue Product Family

Posted on

4

Convert PDF to Excel or Word in Java

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.
Alt Text

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);
    }
}

Output
Alt Text

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);
    }
}

Output
Alt Text

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs