PDF processing control Aspose.PDF function demo: use Java to convert PDF documents to XLS/XLSX

Aspose.PDF  is an advanced PDF processing API that can easily generate, modify, convert, render, protect and print documents in cross-platform applications. No need to use Adobe Acrobat. Additionally, the API provides compression options, table creation and manipulation, graphics and image functionality, extensive hyperlink functionality, stamp and watermark tasks, extended security controls, and custom font handling.

Aspose API supports popular file format processing and allows exporting or converting various types of documents to fixed layout file formats and most commonly used image/multimedia formats.

Various situations may arise when there is a need to export data in tables from a PDF document to an Excel workbook. With PDF to Excel, you can edit data, apply formulas, draw charts, and perform other operations supported by spreadsheets.

In this article, I'll show how to automatically convert PDF to Excel programmatically using Java, and how to convert PDF to XLS and back to XLSX.

  • Convert PDF to XLS using Java
  • Convert PDF to XLSX using Java
  • PDF to Excel – Minimize the number of worksheets

Currently, the Java version of Aspose.PDF has been upgraded to v20.6, which supports converting PDF to CSV and repairing the abnormality of HOCR data. Interested friends can click the button below to download the latest version.

Aspose.PDF for Java下载(qun:761297826)icon-default.png?t=N6B9https://www.evget.com/product/4202/download

PDF processing control Aspose.PDF function demo: use Java to convert PDF documents to XLS/XLSX

Convert PDF to Excel XLS using Java

In order to convert PDF to Excel XLS, just load the PDF document and save it with .xls extension. Below are the steps to perform this conversion.

  • Load PDF files using the Document class
  • Save PDF as Excel XLS using Document.save(String outputFileName, int format) method.

The following code sample shows how to convert PDF to Excel XLS using Java.

// Load source PDF file
Document doc = new Document("sampletable.pdf");
// Convert PDF to XLS
doc.save("workbook.xls", SaveFormat.Excel);

Import PDF document

PDF processing control Aspose.PDF function demo: use Java to convert PDF documents to XLS/XLSX

Output Excel spreadsheet

PDF processing control Aspose.PDF function demo: use Java to convert PDF documents to XLS/XLSX

Convert PDF to XLSX using Java

To convert a PDF to an XLSX spreadsheet, the output Excel format needs to be defined using the ExcelSaveOptions class. Following are the steps to convert PDF to XLSX using Aspose.PDF for Java.

  • Use the Document class to load the input PDF document.
  • Create an instance of the ExcelSaveOptions class.
  • Use the ExcelSaveOptions.setFormat(ExcelSaveOptions.ExcelFormat.XLSX) method to set the output format.
  • Convert PDF to Excel using Document.save(String outputFileName, SaveOptions options) method.

The following code sample shows how to convert PDF to XLSX using Java.

// Load source PDF file
Document doc = new Document("sampletable.pdf");
// Set Excel options
ExcelSaveOptions options = new ExcelSaveOptions();
// Set output format
options.setFormat(ExcelSaveOptions.ExcelFormat.XLSX);
// Convert PDF to XLSX
doc.save("workbook.xlsx", options);

Minimize the number of worksheets in PDF to Excel

By default, Aspose.PDF converts each page in a PDF document into a separate worksheet. However, the API can be customized to minimize the number of sheets in the case of large PDF documents. Below are the steps to do this.

  • Use the Document class to load the input PDF document.
  • Create an instance of the ExcelSaveOptions class.
  • Set the option ExcelSaveOptions.setMinimizeTheNumberOfWorksheets(true).
  • Save PDF as XLSX.

The code sample below demonstrates how to convert a PDF with a minimum number of sheets to XLSX using Java.

// Load source PDF file
Document doc = new Document("sampletable.pdf");
// Set Excel options
ExcelSaveOptions options = new ExcelSaveOptions();
// Set output format
options.setFormat(ExcelSaveOptions.ExcelFormat.XLSX);
// Set minimizing option
options.setMinimizeTheNumberOfWorksheets(true);
// Convert PDF to Excel XLSX
doc.save("workbook.xlsx", options);

Guess you like

Origin blog.csdn.net/m0_67129275/article/details/131826106