is there such a thing as xsl:fo reporting or xsl:fo simulation?
I am trying to determine if MY xsl:fo generated PDF file will exceed one page or not, without actually generating the ou开发者_JAVA技巧tput. We use Apache-FOP 0.95 on our server, and the XML data is being generated using a PHP DOMDocument class before being passed onto an XSL-FO template.
My question:
Are there PHP libraries out there that can simulate xsl:fo output and send me reports that I can use in my application?
Alternatively, is there a way for the Apache FOP itself (or sibling Java app) that sends reports without actually generating a file? I have been reading the FOP documentation, and aside from some things I can not fully understand, I have not been able to find a way to do that from within FOP.
Without actually running the document through the layout engine there's no possibility to "simulate" the document. Also, different FO processors may produce slightly different output, so you can't rely on the result from one to guess on the number of pages of another.
What you can do with Apache FOP 0.95 is generate the so-called Area Tree XML (or intermediate format) which basically outputs the layout result as an XML file instead of a PDF, for example. That XML file could then be inspected using XPath (or XSLT) to determine the number of pages. The XML format is not formally described, but you'll quickly see how you can determine the number of pages. So, by using "-at application/pdf simulation.xml" instead of "-pdf output.pdf" on the command-line, you can produce that XML format. Of course, most of the processing required to produce the final document needs to be done in this case, so re-running the whole document again for PDF production will cost quite some time. The good news is that you can use the AT XML as input again to produce the final PDF so the layout stage doesn't have to be run again (see "-atin" parameter in the documentation).
Another possibility is, of course, to just use a PDF tool to determine the number of pages of the final document.
HTH
精彩评论