Code to convert pdf to Excel in Java

Hi,

Can I have the java code to convert a pdf with tables and images to Excel. Do I need to add temporary license to achieve it.
Thanks.

@swaroopa12

Thank you for contacting support.

I would like to request you to visit Convert PDF to Excel Workbook for your kind reference. Aspose.PDF API works in evaluation limitation mode when a license is not set, i.e. Maximum 4 items of any collection can be processed, and a watermark appears on generated PDF document. If you want to evaluate the API in its full capacity, please set the license as explained in Licensing.

I hope this will be helpful. Please let us know if you need any further assistance.

Can I convert it to xlsx. I tried the sample code and images seem to be lost after conversion.

Thanks.

@swaroopa12

Yes, you can share it to an XLSX file as well. Kindly share input document, code snippet and generated file with us, so that we may investigate further to help you out.

Hi,

Attached is a sample pdf.pdf.pdf (423.8 KB)

Excel doesn’t open, it gives file is corrupted error while opening.

Code used:

public static void main(String args[]) {

	String input = "pdf/pdf.pdf";
	String output = "xlsx/tests-example.xls";
	
	com.aspose.pdf.License license = new com.aspose.pdf.License();

	try {
		
		license.setLicense("Aspose.Total.Java.lic");
		
		ExcelSaveOptions options = new ExcelSaveOptions();
		options.setInsertBlankColumnAtFirst(false);
		options.setMinimizeTheNumberOfWorksheets(true);

		Document doc = new Document(input);
		doc.save(output, options);
		
		

		
	} catch (Exception e) {
		e.printStackTrace();
	}

Thanks,
Swaroopa.

@swaroopa12

I have worked with the data shared by you and have been able to reproduce the issue in our environment. A ticket with ID PDFJAVA-37524 has been logged in our issue management system for further investigation and resolution. The issue ID has been linked with this thread so that you will receive notification as soon as the issue is resolved.

We are sorry for the inconvenience.

@swaroopa12

We would like to update you that the generated file was saved in Excel 2003 XML format and in latest versions of MS Excel it cannot be opened if it has XLS file extension. Please, save the document with “XML” file extension and you will be able to open it in MS Excel. We are improving PDF to XLS conversion. Until then, please use below code snippet (that uses Aspose.PDF and Aspose.Cell API) in your environment.

String input = "pdf/pdf.pdf";
String output = "xlsx/tests-example.xml";

ExcelSaveOptions options = new ExcelSaveOptions();
options.setInsertBlankColumnAtFirst(false);
options.setMinimizeTheNumberOfWorksheets(true);

Document doc = new Document(input);
doc.save(output, options);

com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook(output);        
workbook.save(testdata + "PDFJAVA_37524/out.xlsx", com.aspose.cells.SaveFormat.XLSX);

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Above solution is not working for my pdf for java language.
Getting blank xls file while converting from pdf.
my sample code is
String input = “/home/force/Downloads/week-1-2019-20.pdf”;
String output = “/home/force/Downloads/out.xml”;

	ExcelSaveOptions options = new ExcelSaveOptions();
	options.setInsertBlankColumnAtFirst(false);
	options.setMinimizeTheNumberOfWorksheets(true);

	Document doc = new Document(input);
	doc.save(output, options);

	com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook(output);        
	workbook.save("/home/force/Downloads/data.xlsx", com.aspose.cells.SaveFormat.XLSX);

file2.pdf (104.5 KB)
Sample pdf

@goutam90

Thank you for contacting support.

We have tested the code snippet with your file and generated file contans the data. We have attached generated file for your kind reference. data.zip

Please ensure using Aspose.PDF for Java 19.10 and Aspose.Cells for Java 19.10 in your environment and then share your kind feedback with us.

i can’t download attachment. it say this error : “Sorry, this file is private. Only visible to topic owner and staff members.”

@amiraziz

You are not the owner of this thread which is why the attachment cannot be downloaded. In case you are facing similar issue, please create another post with your files attached there. We will test the scenario in our environment and address it accordingly.