Calculating Pages

There is a good and apparently simple question on the forum today from mysterious user613190 - dont be a number, be a free person to mangle a phrase. It was actually posted yesterday but a man has to rest a little.


In my output I am getting page numbers like

1 of 3 (when output has 3 pages)
2 of 3
3 of 3

But if output has only one page then I need to show like below


Could you help me in this?

Its a simple question, how do I conditionalize (is that a new word I just made up?) the page numbers? Seems straightforward to the uninitiated XSLFO template creator.
'Why cant I count the number of pages in the template and then render one string or another?'
'Well, you can't !'
'Why Not?'
'Because I said so !'
Hang on, hang on, this is sounding like a conversation between my son and I; except it would be about why he can not go to the movies, or hang out at the skate park or maybe ride his dirtbike - it's a power thang and I get irrational sometimes OK!

Getting back to a rational answer ... you still can't and its not because I said so, its because the XSL standards say so. Well that and the fact that the rendering engine at runtime decides how much data/information can fit on a page. To understand the process a little more, when we apply a template against some data, the flow (for the case of PDF) and assume your RTF template has been converted to XSLFO is as follows.

XML + XSLFO  -------> FO ------> PDF
__________             ____
          |                        |
 XSLT Engine          FO Renderer

That FO stage is the Formatting Object - its a big piece of XML that looks similar to extremely detailed HTML with pixel perfect placement of objects on the resulting page. To understand why you can not place 'page' logic in the template you need to know the processes going on. To get to the formatting object its an XSL transformation - at this stage all thats happening is the format and placement of data is applied to the XML data but there is no notion of a 'page' or how much data will fit on that page. The second stage, taking the FO to the PDF output is carried out by the FO renderer - at this point the engine will start to lay the data out on pages, calculating what will fit and then rendering it.

So, you see that any logic around pages in the template is not going to work, its lost and can not be executed in the FO layer, by then all calculations and conditional formatting will have been executed and because there is no notion of what will fit on a page or how many pages there are going to be - by then its a matter of fitting the data onto the page.

What are the options then I hear you ask? Well, we already have some extensions to the standard we have put in to our engine around page rendering. Those of you using the dynamic column solution to get a Z printing format on your PDF output are unwittingly using one of those extensions. We are therefore looking into building a page calculation extension to allow such functionality as is being asked for above - it's coming, not in the next release but some time after that.
What about now, I need a solution! - well one option to is to control the number of lines you want to show per page. If you have that in place then you can comfortably calculate in your template whether you are going to get 1 page or 100 pages of output and then act accordingly. I have covered fixed number of lines per page before and that article should get you on your way. If folks out there have found others, please feel free to share.


Ahhh ... ours is not to reason what users want :0)

Posted by Tim Dexter on February 25, 2008 at 02:41 AM MST #

This seems an odd requirement to me. As a reader I would want to _know_ that this document is a one-pager, rather than guessing. Particularly if I'd printed it out. It's like the "this page left intentionally blank" message: funny the first time you see it, but eventually you see the point. Cheers, APC

Posted by APC on February 25, 2008 at 03:08 AM MST #

In my output I am not getting page numbers like 1 of 3 (when output has 3 pages) 2 of 3 3 of 3

Posted by t ignatius on September 18, 2008 at 09:40 PM MDT #

Hi, In my output I am not gettin page number format in all the pages. It is displaying the footer on odd pages, In the page layout the option of "Different Odd and Even Pages" in unchecked. Thanks in advance. Marcian.

Posted by Marcian on October 02, 2010 at 05:10 PM MDT #

I'm much in need of the capbility to control the insertion of a "this page intentionally left blank" before the start of a new chapter based on whether the chapter starts on an odd or even page. My document is landscape and now chapter should begin on the top page. Have the page calculation extensions been added at this point for me to avail of? Thanks.

Posted by Michal Bonino on May 31, 2011 at 02:28 AM MDT #

Hi Tim,

I am not able to open the article that you said for covered fixed number of lines per page before..could you please send the correct link..


Posted by Srinivasulu on January 11, 2012 at 01:41 AM MST #

Post a Comment:
  • HTML Syntax: NOT allowed

Follow bipublisher on Twitter Find Us on Facebook BI Publisher Youtube ChannelDiscussion Forum

Join our BI Publisher community to get the most and keep updated with the latest news, How-to, Solutions! Share your feedback and let us hear your voice @bipublisher on Twitter, on our official Facebook page, and Youtube!


« June 2016