jQuery in Action, 3rd edition
The moose likes JSP and the fly likes opening PDF from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "opening PDF from JSP" Watch "opening PDF from JSP" New topic

opening PDF from JSP

kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 323
Hi all
I want to open a pdf file from a JSP. I have seen a lot of code which reads a file and output it as PDF.But my requirement is that, i have a object and i want to use that object to fill up data in pdf from a jsp. i.e opening a pdf file from JSP which will comtain data from my object(suppose customer object)
Is there any way to do that ??

Failures are practice shoots for success.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

So you want to programmatically create the PDF? You'd need to look at something like The Big Faceless Java PDF library for that.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
you can use itext as well...its really flexible.......it makes things easier.


What you have to do is: provide the pdf file.

What itext does for you is open the pdf file, collect the names of the fields for you and populate them for you and write it back to the pdfwriter. Once you have the pdf (as a byte array) you can output it using servletoutputstream.

getting the fields is as:
PdfReader pdfReader = new PdfReader(pdfInBytes);
PdfStamper stamp = new PdfStamper(pdfReader, out);
AcroFields form = stamp.getAcroFields();

for (Iterator i = pdfReader.getAcroForm().getFields().iterator(); i.hasNext() {
//get each field
PRAcroForm.FieldInformation field = (PRAcroForm.FieldInformation) i.next();
form.setField(field.getName(), your value you want to set);

"In theory, there is no difference between theory and practice. But, in practice, there is."<br /> - Jan L.A. van de Snepscheut
I agree. Here's the link: http://aspose.com/file-tools
subject: opening PDF from JSP
jQuery in Action, 3rd edition