File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes pdf generator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "pdf generator" Watch "pdf generator" New topic

pdf generator

Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 148
I have a functionality where I have generate pdf from the reports that are rendered using jsp. I have to write a common PDF generator that generates pdf on fly.

You all know that with Jsp's report data would be converted to html format and displayed onto the broswer. Now, when the user want to see the same data in PDF format, do I have to make a call onto the pdf generator class that would make call onto my business class to get the data from the database and convert that into XML-FO format?. I don't want to have pdf generator class for each report.

I am not sure how I should have to proceed with this and what is the best solution and in general how this is done.

I am new to XML and XLST and I am not sure how to go about this.

I would appreciate if any one could help me in handling this
Thank you
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
I don't think you should tie your PDFGenerator class to the rest of your application too tightly. In my opinion, the PDFGenerator class should take an input XML document, the XSL stylesheet document for converting that particular XML into XSL-FO, and then run the XSL-FO through the XSL-FO engine to generate PDF. Nothing more.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 148
Thank you Lasse Koskela,
I really appreciate your reply.

I am currently in a phase where I have to identify all classes that I need for my PDF generator. I would really appreciate if you could help in suggesting if the approach I am thinking is correct or suggest best approach.
Approach 1:
1. JSP would send a request to generate a report in pdf format to Action class which inturn makes a request on to my business class.
2. Business class inturn would send a request to the DB class.
3. DB class would get the data from the database and return the data in the form of value objects to the business class.
4. Business class then send that collection to the DOMGenerator that converts data in the value objects to DOM Document and return DOM document to the business class.
5. Business class inturn would return DOM Document to the Action class.
6. Action class would send the DOM Document and xsl file to the PDF generator that generates xsl-fo and transfor XSL-FO into pdf.

1. With the above approach, will there be any performance issues with creating DOM Document?. As I may get thousands on records from the database
2. General question: With this approach will there be any memory issues as DOM document is built in memory. With respect to memory and network traffic will there be any difference between returning collection of value objects to returing DOM document.
Approach 2:
Same as above approach 1. Except that instead of converting value objects to DOM Document on EJB side. Send the value objects to the web container. Which would convert them into DOM Document then to XML then to XSL-FO and finally to PDF.

Please Help me out. I have to present this to team on monday

Thank you
[ September 26, 2004: Message edited by: Saritha ventrapragada ]
Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 148
With lots of experts out there.. Please help me with this pdf generation stuff..

How I should approach.
1. I have a value object which need to be converted to xml. I don't want to save xml file onto hard disk. Hence I am thinking of creating Document. and then generate SourceStream from Document which can be passed to the treansform method.

I guess with this I am holding whole data in memory. As I get thousands and thousands of records, I am not sure if there will be any OutOfmemory constraints.

Please help me out.

Else, please post the general approach that should be followed.

Please Please Please
[ September 28, 2004: Message edited by: Saritha ventrapragada ]
I agree. Here's the link:
subject: pdf generator
It's not a secret anymore!