• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Publishing PDF From XML,XSL using FOP

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Part of my project requires outputing PDF document from the data gathered from html form. My current approach is embedding the FOP tool in my Java code and pass to it the dynamically generated XML file, a specific XSL stylesheet file and the PDF file name to be used and let FOP do its job. This works pretty
well.
My question is, can this process be done soley in memory, i.e. no intermediate XML & XSL files (they are stored in memory somehow) involved? If this can be done can anyone care to illustrate some code in Java?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can do these things in memory. Although I am still learning, the key seems to be DOM objects.
First, build a DOM object representing your data. I use DocumentBuilderFactory.
Next, transform it using TransformerFactory. In the following code snippet, the transform uses a DOM object and an XSL file on disk.

Finally, render the formatting object as a PDF file.
I am not sure this is the best way to do it, but it does work. I would like to hear other opinions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!