Template: Make room for total on last page

Template: Make room for total on last page

If you're working with a standard business document, you're likely using the header and footer in your template. A simple example is provided in the section, Template: Header, footer and body area.


However, you might have a specific requirement for the footer, such as needing extra space for the total at the bottom of the last page. Naturally, you wouldn't want to reserve this additional space on the pages before the last.

The solution you choose will depend on how you wish to position the total. You likely want one of the following options:

  1. You may want to display the total of the document in a flexible position – just after the last detail line.
  2. The alternative is to output the total in a fixed position in the bottom of the last page.

Place the total after the last detail line

If you want to insert the total after the last detail line, then you should insert the total in the body of the template and right after the repeat loop, that outputs all the detail lines like below:


Here you may notice, that the container, that contains the total has a dynamic position. The footer contains the elements, that are to be inserted in a fixed position. This solution works independently on if you also have a fixed container in the footer e.g. to force a bottom margin. A general bottom margin can also be defined on the page element.

Output the total in a fixed position (in the bottom) of the last page

If you want to insert a larger footer on the last page of your document, then you need consider the two footer sizes. You might have one footer size on the initial pages and larger footer size on the last page. The limitation however is, that the footer height is in principle a fixed height, but there is still a way to add more space on the last page.

First you need to consider the height of the two footers:

  1. The fixed (smaller) footer on the initial pages. We can call the height of this footer X.
  2. The fixed (larger) footer on the last page. We can call this height Y.

We need to reserve extra space after the last detail line. This extra space is the difference between the two, which we can call Z. So Z is calculated as Y minus X.

These measurements are illustrated below:

Initial pages (except the last page):


Last page:

So as an example if the small footer is 2 cm and the large footer (on the last page) is 6 cm, then the extra space to reserve is 4 cm. 

In the flow of the detail lines we need to reserve the extra space which is the difference in height (Z) on the last page only.


That is done with these elements:
1) Introduction of a variable, LastPage, which initially is set to 'No' and then change the value to 'Yes', when we have reached the last page.
2) We insert an invisible container with the height of Z (4 cm in this case) in the body section (with a dynamic position) just before the LastPage variable is changed into 'Yes':



(The container with the height=Z is an invisible container, that might overlap the extra large footer on the last page).

In this way the details will keep away from the bottom of the last page in an area with the height of Z+X.


The contents of the footers

The setup above only reserves the space for the right sized footers, but we also need to consider the contents of these two footers.

We need a condition in order to determine if the current page is the last or not, so for that we add a variable, LastPage which should change its value when all detail lines has been output (then we know that the current page is the last. 

In this example the variable, LastPage is initially set to the value, "No" and changed to the value 'Yes', when all detail lines (including the extra space). We use that for conditionally adding the extra footer on the last page like below:



 Based on the value of the variable, LastPage the extra container is only inserted on the last page.

The important things to notice are:

  1. The container that is to be inserted on the last page only is inserted first - before the standard footer.
  2. This extra container must have a fixed position and a negative position in the Y-direction. This is how it looks in this sample template:
  3. The small footer is inserted after the previous container might have been inserted.
The example above is included as an attachment (DynamicFooter1.ift)

Advanced: Total with variable height in a fixed position on the last page

Let us consider an even more complicated example: That the total is to be placed like in the example above, but the height of the total container (referenced as Z above) is not fixed, but variable. In order to do this we need to add a few changes to the template created above.

To illustrate that we here define a variable named TotalHeight, which is set in the top of the template and that is the height of the total section in cm:


Now we need to refer to this variable instead of the fixed 4 cm, that we used above.

That is now referenced in the container height in the body section:

And we also need to use the variable, TotalHeight to set the dynamic height and position of the total container in the footer section:

The position is calculated as:
-1*$TotalHeight*28.3465
The height is multiplied with the number 28.3465 as we need to convert from cm into 72 DPI (multiply with 72 and divide by 2.54).

The height is the container is simply the value of the variable, TotalHeight: