Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

opening PDF from JSP

 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
Thanks
kundan
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want to programmatically create the PDF? You'd need to look at something like The Big Faceless Java PDF library for that.
 
Preetham Chandrasekhar
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use itext as well...its really flexible.......it makes things easier.

http://www.lowagie.com/iText/

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);
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic