File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes printing report in PDF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "printing report in PDF" Watch "printing report in PDF" New topic
Author

printing report in PDF

s mit
Greenhorn

Joined: Apr 23, 2003
Posts: 1
hi all
my query is i want to print a report in PDF consisiting of Static and Dynamic fields. How to insert the dynamic fields in the PDF document.

thanks in advance
Sumeet
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Check out these two open source tools:
JasperReports:
Free Java report-generating library. XML report templates are used to generate ready to print documents using data from customizable data sources, including JDBC. The output can be delivered to the screen, printer, or stored in PDF, HTML or XML format.
iText, a JAVA-PDF library:
This library contains classes that generate documents in the Portable Document Format (PDF) and/or HTML.


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
First of all, which PDF library are you using?
- iText
- BigFaceless
- PDFlib
- GNUjpdf
- Some other?
There are also some commercial products specialized in generating PDF reports based on database tables, XML documents, etc.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
I have done this using xsl-fo and FOP. I've been quite pleased with the results.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Jason Menard:
I have done this using xsl-fo and FOP. I've been quite pleased with the results.

Have you used iText? If so, how does it compare with FOP? Or is it similar enough that there is a comparison. I find iText pretty easy. Do just looking for opinions.


GenRocket - Experts at Building Test Data
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Originally posted by Gregg Bolinger:
Have you used iText? If so, how does it compare with FOP? Or is it similar enough that there is a comparison. I find iText pretty easy. Do just looking for opinions.

I haven't used iText so I really can't offer a comparison. I will point out that FOP is just an xsl-fo processor programmed in Java, which can be used stand-alone but also has an API which you can use to call it from within your code. It takes an xsl-fo document and can ouput pdf or a few other outputs.
Is an fo based solution for you? If you want a non-proprietary solution, yes. Since xsl-fo is a w3c standard, any FO processor would be able to render an fo document, not just FOP. If you have a particular reason that using XML technologies would make sense for your project, then using something like FOP would be a good direction to head in.
Our requirements were to make a complex multi-page printer-friendly version requiring precise layout of some web-based material. The basic flow we used was to produce a DOM (using JDOM) of a heirarchy of Java objects. Once we had our DOM, we transformed it using an xsl stylesheet to provide the proper xsl-fo markup, as well as a sprinkling of svg. We took the transformed DOM, and fed it to a servlet (in this case acting as a view for a Struts application) which rendered the pdf using FOP and produced an output stream of type application/pdf.
The upside for us was that we will be able to re-use portions of that, particularly marshalling the objects to xml, for other requirements we have coming down the road. Additionally it is a relatively simple thing to do to change the xsl stylesheet if we have any tweaks we need to make, and we have maintained separation of our data and presentation.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Just as a side note, I was wondering whether any of these mentioned libraries (especially iText) are capable of streaming PDF files? I mean, pushing out blocks instead of creating the whole document in-memory and then flushing that out.
I had to come up with an export feature for XLS and none of the available libraries supported true streaming so I had to write a simple report generator, which wrote the BIFF8 blocks one by one (they had to be written in a certain order required by the spec, which kind of made the code unreusable but...)
Ron Perich
Ranch Hand

Joined: Mar 25, 2003
Posts: 41
Originally posted by Jason Menard:
I have done this using xsl-fo and FOP. I've been quite pleased with the results.

I'll second that. FOP was easy to use and learn. But watch out for memory consumption. I've heard this is a problem with a lot of these tools. FO has some techniques for reducing the memory footprint that should be followed.
Cheers,
Ron


RP
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: printing report in PDF