Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Apache FOP

 
Ranch Hand
Posts: 2379
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 2379
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I request the moderator to move this post to xml forum.
 
Balaji Loganathan
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2379
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2379
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2379
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you look at the link i gave above ?
AW i will psate the code for you here
 
Balaji Loganathan
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the full example of servlet-FOP
 
Ashik Uzzaman
Ranch Hand
Posts: 2379
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya, got thta just after posting here. Thanks Balaji for your immense help.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I missed this earlier. Moving to XML forum...
Here you go.
[ March 31, 2004: Message edited by: Barry Gaunt ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic