Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert ms-Excel file to Pdf in java?

Tags:

java

excel

pdf

Because I have used JXL api for excel but now I want to convert it to Pdf file so please tell me how to change my code to convert excel to pdf?

like image 602
user3800534 Avatar asked Nov 27 '25 09:11

user3800534


1 Answers

You could use iText to create a pdf file in java and use Apache POI to access the data in the MS-EXCEL file. If you combine both, you could convert your excel file.

A raw example is given here

Also, there is this new API: You can try Aspose.Cells for Java which allows you to convert Excel file to PDF in Java applications. It doesn't require MS Office/OpenOffice etc to be installed on your development or deployment machine. It also works on both Windows and Linux platforms. The code is very simple as shown below:

    //Instantiate a new workbook with excel file path
Workbook workbook = new Workbook("F:\\FileTemp\\Book1.xls");

//Save the document in Pdf format
workbook.save("F:\\FileTemp\\MyPdfFile.pdf", FileFormatType.PDF);
like image 91
Tanveer Shaikh Avatar answered Nov 29 '25 22:11

Tanveer Shaikh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!