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?
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.