aspose file tools*
The moose likes XML and Related Technologies and the fly likes Apache FOP 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 » Engineering » XML and Related Technologies
Bookmark "Apache FOP" Watch "Apache FOP" New topic
Author

Apache FOP

Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

I have used Apache FOP 2 years earlier last time and now using again. I need to clarify a few points that I could not find out in documentaiton and mailing list after a quick search.
In our Struts based application, I have the beans that hold data and I want to generate reports using that. Now my available options are ----
1. Dump that bean with all its properties and child properties to an XML file. Use FOP's XSLT processor to generate XSL-FO file. Now use that FO file to genereate PDF.
My Query: How am I going to use that XSLT processor? Should I hard code in a java class that will generate the XSL-FO from the XML file? Hard coding is not what I like. Where in FOP's documentaiton I can find the steps needed?
2. Dump the bean in a nice way so that I can directly generate output as XSL-FO file rather than going thru the intermediate translation phase.
My Query: Is it really possible? How? Then where I'll say the rules for FO layout in my code?
Looking forward to your help.


Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

Hei Pals,
I found some examples in fop distributions /examples/embedding/java/embedding dir. I also got to know from the documentaiton that, a good strategy should be
1. Dumping my bean as an XML file. (did it earlier)
2. Write down an XSL file for the generated XML file. (here i was confused)
2. Using Xalan transform the previously generated XML file, following the rules I wrote in XSL file, generate an XSL-FP file.
3. Then using FOP processor, generate pdf file using the just-now genereated XSL-FO file. (did it earlier)
Anyway, I didn't find there any example that hints about generating Obj2FO. ... Is it possible really? (my previous question#2)
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
I request the moderator to move this post to xml forum.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Ashik uzzaman:

1. Dumping my bean as an XML file. (did it earlier)
2. Write down an XSL file for the generated XML file. (here i was confused)
2. Using Xalan transform the previously generated XML file, following the rules I wrote in XSL file, generate an XSL-FP file.
3. Then using FOP processor, generate pdf file using the just-now genereated XSL-FO file. (did it earlier)
Anyway, I didn't find there any example that hints about generating Obj2FO. ... Is it possible really? (my previous question#2)

Ashik, I would suggest to convert your data beans to .FO directly, unless you need to use the data XML for another process. Now you can directly convert fo to pdf using servlet or javabean-jsp
On the other side, its better to out the javabeans data as xml where you can use a xslt to convert xml to fo then to pdf. by this way you can edit xslt seperately.(this will help you to avoid re-compiling your javabeans for correcting any changes in the output report)
xml/FO to pdf converiosn using servlet can be found here http://xml.apache.org/fop/servlets.html
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

Thank you Balaji for the hints. What I did till now is, prepared both methods to generate PDF through XML+XSL-->XSL-FO-->PDF and directly dumping a bean as an XML-FO through velocity as XSL-FO and thru FOP to PDF. All these are run now thru command prompt and now wokring for web version (in our struts based application).
Now the decision to make is....i can either create the FOP in-memory and display my web clients directly from there or I can save the generated fop to a server directory, say "reports" and use sendRedirect() to display the report. Which one is a better idea and why? Can you refer any sample link or discussion on this?
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Ashik uzzaman:
Now the decision to make is....i can either create the FOP in-memory and display my web clients directly from there or I can save the generated fop to a server directory, say "reports" and use sendRedirect() to display the report. Which one is a better idea and why? Can you refer any sample link or discussion on this?

Sorry i missed this thread.
Good question, In one of my project, I use to store the generated pdf in temp folder as i have to email them to the user apart from displaying on browser screen. For your case i would suggest to display the PDF stream directly, Because if you store them into a temp folder, then you have to write a method which will read the pdf file using file inputstream reader then give that to printWriter of servlet. WHEREAS with other option you will give the FOP processed stream to printWriter directly.
Make sense ??
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

Yes, makes sense, thank you Balaji. I am preparing it in a way so that it can be used both from my struts-based applciation and a command prompt tool. I'll finish it by next 2 days, hope to share the outcome.
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

Well I was using a code similar to the following from my ReportGenerator class that will b used both from my command line tool and struts-based webapp to generaete a PDF from an FO file.

But we want to generaete the file without using shell, rather directly calling FOP's methods that do this file generation staff. May anyone hint which methods can that be in FOP. I am searching around the FOP documentation for some time.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Did you look at the link i gave above ?
AW i will psate the code for you here
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
here is the full example of servlet-FOP
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

Ya, got thta just after posting here. Thanks Balaji for your immense help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Apache FOP