views:

54

answers:

3

I have a webpage with a export option to PDF. I have to display the contents of the page in the PDF. Currently I use iText PDF Library to generate PDFs. The problem is creating PDF with iText is quite a challenge. Moreover we get frequent layout/UI changes for the webpage, so we have make the same changes to PDF.

Is there any way i can convert my JSP output to PDF. Like for example "if we set the content type to contentType="application/vnd.ms-excel", a JSP table can be rendered as Excel document.

+3  A: 

Have you checked Jasper Reports ? It has the concept of XML templates. Also same template can be used to generate Word / XLS / PDF/ CSV / XML output.

Script Runner
A: 

You should check wkhtmltopdf.

Marko
A: 

You don't need to change the iText code generation if you use it in combination with Flying Saucer (a.k.a. XhtmlRenderer). It's then basically as simple as:

String inputPath = new File("/file.xhtml").toURI().toURL().toString();
OutputStream outputStream = new FileOutputStream("/file.pdf");

ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(inputPath);
renderer.layout();
renderer.createPDF(outputStream);
outputStream.close();

You can find a blog with more code samples here.

BalusC