Spire.PDF for Java offers the PdfDocument.saveToFile() method to convert PDF to other file formats such as Word, Excel, HTML, SVG and XPS. When converting PDF to Excel, it allows you to convert each PDF page to a single Excel worksheet or convert multiple PDF pages to one Excel worksheet. This article will demonstrate how to convert a PDF file containing 3 pages to one Excel worksheet.
Install Spire.PDF for Java
First of all, you're required to add the Spire.PDF.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.pdf</artifactId> <version>10.10.7</version> </dependency> </dependencies>
Convert a Multi-page PDF to One Excel Worksheet
The detailed steps are as follows:
- Create a PdfDocument object.
- Load a sample PDF file using PdfDocument.loadFromFile() method.
- Set the PDF to XLSX conversion options to render multiple PDF pages on a single worksheet using PdfDocument.getConvertOptions().setPdfToXlsxOptions() method.
- Save the PDF file to Excel using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.*; import com.spire.pdf.conversion.XlsxLineLayoutOptions; 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"); //Set the PDF to XLSX conversion options: rendering multiple pages on a single worksheet pdf.getConvertOptions().setPdfToXlsxOptions(new XlsxLineLayoutOptions(false,true,true)); //Save to Excel pdf.saveToFile("out/ToOneSheet.xlsx", FileFormat.XLSX); } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.