Java/ Convert PDF to Excel

When a PDF file contains table, you may need to convert it to Excel for further processing. In this article, you will learn how to convert each PDF page to a single Excel worksheet as well as how to convert multiple PDF pages to one Excel worksheet by …


This content originally appeared on DEV Community and was authored by carlwils

When a PDF file contains table, you may need to convert it to Excel for further processing. In this article, you will learn how to convert each PDF page to a single Excel worksheet as well as how to convert multiple PDF pages to one Excel worksheet by using Free Spire.PDF for Java.

Two Methods to Import the JAR Dependency

Method 1: You can download the free library and unzip it. Then add the Spire.Pdf.jar file to your project as dependency.
Method 2: Or you can directly add the jar dependency to maven project by adding the following configurations to the pom.xml.

<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>4.4.1</version>
    </dependency>
</dependencies>

Convert a PDF File Containing Three Pages to Three Excel Worksheets

Step 1: Create a PdfDocument object.
Step 2: Load a sample PDF file using PdfDocument.loadFromFile() method.
Step 3: Save the PDF file to Excel using PdfDocument.saveToFile() method.

import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;

public class ToXLS {
    public static void main(String[] args) {
        //Create a PdfDocument object
        PdfDocument pdf = new PdfDocument();
        //Load a sample PDF file
        pdf.loadFromFile("C:\\Users\\Administrator\\Desktop\\Members.pdf");
        //Save to Excel
        pdf.saveToFile("output/ToExcel.xlsx", FileFormat.XLSX);
    }
}

ToExcel

Convert a PDF File Containing Three Pages to One Excel Worksheets

Free Spire.XLS for Java offers the PdfDocument.getConvertOptions().setConvertToOneSheet(true) method to convert multiple PDF pages to one Excel worksheet.

import com.spire.pdf.*;

public class ManyPagesToOneSheet {
    public static void main(String[] args) {

        //Create a PdfDocument object
        PdfDocument pdf = new PdfDocument();

        //Load a sample PDF file
        pdf.loadFromFile("C:\\Users\\Administrator\\Desktop\\Members.pdf");

        //Convert multiple PDF pages to one Excel worksheet
        pdf.getConvertOptions().setConvertToOneSheet(true);

        //Save to Excel
        pdf.saveToFile("output/ToOneSheet.xlsx", FileFormat.XLSX);
    }
}

ToOneSheet


This content originally appeared on DEV Community and was authored by carlwils


Print Share Comment Cite Upload Translate Updates
APA

carlwils | Sciencx (2021-12-03T06:39:19+00:00) Java/ Convert PDF to Excel. Retrieved from https://www.scien.cx/2021/12/03/java-convert-pdf-to-excel/

MLA
" » Java/ Convert PDF to Excel." carlwils | Sciencx - Friday December 3, 2021, https://www.scien.cx/2021/12/03/java-convert-pdf-to-excel/
HARVARD
carlwils | Sciencx Friday December 3, 2021 » Java/ Convert PDF to Excel., viewed ,<https://www.scien.cx/2021/12/03/java-convert-pdf-to-excel/>
VANCOUVER
carlwils | Sciencx - » Java/ Convert PDF to Excel. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/03/java-convert-pdf-to-excel/
CHICAGO
" » Java/ Convert PDF to Excel." carlwils | Sciencx - Accessed . https://www.scien.cx/2021/12/03/java-convert-pdf-to-excel/
IEEE
" » Java/ Convert PDF to Excel." carlwils | Sciencx [Online]. Available: https://www.scien.cx/2021/12/03/java-convert-pdf-to-excel/. [Accessed: ]
rf:citation
» Java/ Convert PDF to Excel | carlwils | Sciencx | https://www.scien.cx/2021/12/03/java-convert-pdf-to-excel/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.