tags:

views:

28

answers:

1

Hi, I am trying to determine if MY xsl:fo generated PDF file will exceed one page or not, without actually generating the output. 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.

Any advice is much appreciated.

A: 

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

Jeremias Märki
Thanks for the input, Jeremias. I am trying to avoid generating a real file. As I look through much of the documentation it looks like I do not have a choice but to generate a real file and use FOP's large memory consumption.What PDF tool would you suggest to use to count pages? I was thinking of using fpdi (http://www.setasign.de/products/pdf-php-solutions/fpdi/).
topmulch
I don't do PHP myself so I can't recommend anything PHP-specific. FOP itself can report the number of pages it generated. But that requires to interact with FOP using Java code.
Jeremias Märki