views:

453

answers:

4

I have created a JSP with various fields. I want to provide an option to export the page to a PDF before submit but after the user fills in the form.

How can this be achieved? I am struggling with this problem past many days and not able to get solution.

A: 

Just use the Print option in Firefox 3.5. It has an option to print to PDF file. Alternatively, you can use PDFCreator or some other virtual printer software that writes to PDF file instead of printing on paper.

Milan Babuškov
Let me guess: you're either on a Mac, or you installed a PDF printer. I'm running FF 3.6 on Vista and I don't see a PDF printer. You usually need to install a PDF printer for something like this to work.
Matt Ball
Actually, I'm not Linux. You mean there is no "print to file" option in Windows version of Firefox?
Milan Babuškov
That is correct. You can however obtain a driver that will look like a Windows printer entry, while in reality acting as a print-to-file gateway. Some of those might be free, others cost money.
Pointy
Yes that option is provided. But in addition a create PDF option is needed. The pdf should be a blue print of JSP. I mean all the textboxes with values entered by the user.
Asha
A: 

I want to provide an option to export the page to a PDF before submit but after the user fills in the form.

This is not possible at the server side as the information isn't submitted to the server side yet. Your only resort is the browser capabilities and the knowledge of the user how to use them.

If you can live with changing the flow to submitting into some result page and providing an link to export the current result page to a PDF file, then combine this answer with iText.

BalusC
ok.. Then is it possible to create a pdf at specified location locally after submit? The pdf should be a blue print of JSP. I mean all the textboxes with values entered by the user.
Asha
Only at the server side. You cannot control the location where the file will be saved at client side.
BalusC
+1  A: 

You might want to look into the FlyingSaucer project. It's a mechanism for producing PDF files from XML documents, and in particular from a fairly strict XHTML doctype. It really works quite well, and it supports some CSS3 features for doing things like page headings, intra-document bookmarks (like links), and is generally pretty well-behaved about CSS rules. I don't think it does forms, but you could probably fake that if it's going to end up as a non-interactive document anyway.

Link: https://xhtmlrenderer.dev.java.net/

(If it's not clear, this'd be a server-side solution. The form would have to be posted, and your server would build the PDF and ship it back to the client.)

Pointy
A: 

If you are trying to output a report you can look at display table: http://displaytag.sourceforge.net/1.2/. It comes with a simple servlet filter that will allow you to click a simple link and export to pdf, excel , etc.

Nathan Feger