XSL-FO Designer for Apache FOP


12. The running totals example explained

A very commoun requirement is to have a page footer with the subtotal of the items in the current and previous pages and a total amount at the end of the document. The running totals example located in


shows how create the subtotal item at the end of each page. The output of this example is a 2 page document, in the first page the label "Subtotal" will be generated, together with the sum of all items in the page

in the second page the text is "Total" and the value is the sum of all items in the document.

to achieve this result, two items in the detail area must be selected, one will be the LineAmount field which needs to be summed up, and the other can be any field, in this case the article field has been taken:

The LineAmount field has the property Use for Subtotal set to Yes and the subtotal type SUM will cause the values of this field to be summed up during the PDF generation.

The Article field will be used to create the "subtotal" and "total" labels. Note the subtotal type is now CONSTANT and the two constant value fields have been filled with the correct value.

To finish up the set up, the 2 fields in the page footer must reference the subtotal field in the detail section.