Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

pdf and Java

  Asked By: Nisha    Date: May 28    Category: Java    Views: 545
  

I am developing a jsp based web application. I have one query
I want to show a table in PDF format when the user clicks a link
download as pdf . can any one help me in coding this application

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Grady Stewart     Answered On: May 28

Itext (i think it is on source forge) is a pdf  API that isn't too bad to
use. IText is the jar files that Jasper reports uses to create it's PDF
reports.

To make the link downloadable when you click it you need to make the
link give a post/get request that tells it to send the result as a stream.

<begin crappy code example>

res.setContentType("application/pdf");
ServletOutputStream out = res.getOutputStream();
PDFWriter writer = new PDFWriter(action, type, ideas);
try {
writer.generateDocument(out);
} catch (DocumentException e) {
System.err.println("ARRGGGHH");
}
out.close();

</crappy code example>

Ok before that scares anybody :) this bit of code was from a quick
experimental spike from a project and this code was never really
developed (so it is a bit dirty (but it works).

The PDFWriter Object is the the actual JavaBean that creates the PDF
document (it is really, really ugly in there).

So what happens here is that I set my response content type to be a
"application/pdf", this tells my browser that the garbage of text coming
up is of course a PDF document.
I then write the PDF as a stream onto the response stream of the servlet.

 
Answer #2    Answered By: Brendan Smith     Answered On: May 28

If you want to generate pdf  in a specific format  then using FOP tool
from jakarta you can very well generate pdfs by putting data in xml
and formating it with the help  of xslt.

 
Answer #3    Answered By: Faiza Mian     Answered On: May 28

Just incase anybody else looks for FOP, it isn't under the jakarta site,
it is under apart of the xml project at apache at
http://xml.apache.org/fop/ :)

 
Didn't find what you were looking for? Find more on pdf and Java Or get search suggestion and latest updates.




Tagged: