The presentation below will try to guide you how to do it.
If you want to contribute with another solution, please feel free to contact me.
XLS to PDF with Java
You can use OpenOffice.org(must be available on the same computer or in your network) for document conversion.
Besides XLS to PDF, there are also possible other conversions:
doc --> pdf, html, txt, rtf
xls --> pdf, html, csv
ppt --> pdf, swf
html --> pdf
import officetools.OfficeFile; // this is my package, officetools.jar // uses streams for I/O FileInputStream fis = new FileInputStream(new File("test.xls")); FileOutputStream fos = new FileOutputStream(new File("test.pdf")); // suppose OpenOffice.org runs on localhost, port 8100 OfficeFile f = new OfficeFile(fis,"localhost","8100", false); f.convert(fos,"pdf");
Another feature: it is possible to read and write an Excel using getCell and setCell methods
import officetools.OfficeFile; FileInputStream fis = new FileInputStream(new File("original.xls")); FileOutputStream fos = new FileOutputStream(new File("updated.xls")); OfficeFile f = new OfficeFile(fis,"localhost","8100", false); // update a cell in a column f.setCell(1, 3, "10"); f.write(fos);
How to obtain this solution
officetools.jar is not free(in order to sustain future developments), but it has a very reasonable price.
Available: as jar or as jar+sourcecode. In both cases you get project details, javadoc, setup instructions, examples.
If you want to use this solution in your projects, please contact me for a price quotation: