An Oracle blog about BI Publisher

Anatomy of a Template III - Page Totals and Last Page

Finishing up on this series we will now add a page total and a region that needs to show only on the last page of the document.

Page Totals - as many of you know we have direct support for page totals. You register a page total object in the template and then place it where its required to be rendered. The total is not actually calculated until the rendering engine starts to layout the data on the page, thats the only point at which the engine knows how many 'line' can fit on the page. In our case we know how many lines we are going to fit because we have fixed the number of rows before the rendering engine starts. We also already have those lines loaded into a variable 'invLines' so calculating a total is going to be relatively straightforward.

<?sum($invLines[(position()>=$start) and (position()<($start+$lpp))]/LINE_EXTENDED_AMOUNT)?>

Here's an XPATH expression again inside the '[ ]', this limits the number of rows we want  to sum. it's like a 'where' clause on our data.

If we wanted the word 'Continued ...' to be shown we test the current record position against the total number of lines for the invoice. If they were not equal then we would show the 'Continued ...' string.

Last Page Only - again we now have native support for this when you do not know how much data is going to fit on a page with 5.6.2. In this case thou, we know how much data is going on the page and can ensure that a section on prints on the last page. Take a look a the template, there is a table to hold the summary/special instructions for the invoice at the end of the template. All we have done is wrap an if condition around that table:

<?if:count($invLines) < $start+$lpp?>

This checks to see if we have reached the end of the invoice lines section and if so then render the summary section i.e. on the last page. Then we close out the if condition. To get the table to appear at the bottom of the last page you'll have notived that we created a two celled table and put the line table in the top cell then the summary in the lower one and then drageed the cell border down the page to position the summary at the bottom of the page.

We now have an all singling all dancing invoice template, the features we added were:

1. A fixed number of rows per page,
2. 'Filler' space for lines, because that last page may only have 3 lines but you want to maintain the layout
3. Page totals or 'Continued' in place of a total
4. Last page only content
5. Header and page number resetting as we hit each new invoice in the batch.

The final template, data and output are available here.

We can now take some of those individual features and apply them to pretty much any other document whether than be a batch of purchase orders or a single standard letter showing outstanding invoices. Hope it's been helpful.

Join the discussion

Comments ( 7 )
  • Donn Shumway Tuesday, April 10, 2007
    This is fantastic. I very much appreciate this article. It has explained a lot. Question: How would this template be modified to place the Totals at the bottom of the page and allow any number of lines based on the remaining space between the Header and Section footer? All your help is greatly appreciated.
    Donn Shumway
  • Dave Bayard Tuesday, April 10, 2007
    Good post. Any ideas on how you would combine this with grouping? For instance, if my invoice has a line type of PARTS and a line type of LABOR?
    I want to use the template's features (especially the lines per page and last page only) but I also want to do a group by as I go through the lines.
    For instance, I want to show all of the PARTS lines first, then all of the LABOR lines.
    You used a for-each:$invLines.
    In my example, I am wondering how I reconcile the $invLines to something like:
    for-each-group: Lines; Expenditure_Category
    Have you built a template that does some grouping as well?
  • Karan Friday, February 19, 2010
    Excellent article to get me started on Invoice printing with oracle BI publisher During implemeting the clients requirement I have come across few sticky issues which i am not able to resolve. Your help will be greatly appreciated -
    1. I started by using "Lage Page" native support of Oracle BI publisher ti display deduction logic. This worked fine as long as only one invoice needs to be generated at a time. However now i need to generate 10000 invoices in single PDF. As a result the deductions section only appear for the last invoice. Hence LastPage placeholder is not working for us. Is there any solution to it.
    2. We tried implementing using logic from your template. However our input XML is much more complex as it has 3 different groups and we need to print the invoice lines within invoice as per the groups. Hence the above logic was not working. Also sometime a single invoice line gets printed on multiple lines and the above logic did not work correctly.
    3. Our Data Model basically use data template which combines the data into hierarchy model.We tried using bursting on the data generated from the data model but it threw an exception when generating the files.Does bursting works with data template?
    Anticipating your help on this.
    Thanks in advance
    Kamlesh Bafna
  • Susan Chan Saturday, July 17, 2010
    Hi Tim,
    You said "If we wanted the word 'Continued ...' to be shown we test the current record position against the total number of lines for the invoice. If they were not equal then we would show the 'Continued ...' string."
    How do we do it? Can you show us the XPATH?
  • Black Ass Doll Friday, July 23, 2010
    As a Newbie, I am always searching online for articles that can help me. Thank You.
  • kl&auml;der online Wednesday, August 18, 2010
    Interesting reading
  • Christina Wednesday, April 25, 2012

    Hi Tim, great article. We've implemented a new AR invoice using a similar format. However, we have recently noticed an issue with regard to the Special Instructions. When printing a single invoice at a time there is no issue but when printing a batch or a range of invoices the special instruction from the first invoice shows on all the invoices printed, rather than that invoices special instructions. Any suggestions on how to fix this?

    Thanks, Christina

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.