Monday, October 29, 2012

Printing footer on report last page without reserving white space in all pages (AX 2009)

AX 2009 (and prior versions) always had a problem in printing report's footer.

If you want a footer to be printed only in the last page of the report, in the bottom part of the page, you have to condition the last page print by code.

This works pretty well, except that the footer space is reserved in all of the pages, leaving a white space hole in all the pages!

That's a problem in report like Invoices, where you have a big footer with totals and so on.

Normally you would make the footer appear in all pages, so the white space hole will be filled, but that's not a proper solution for some customers.

I found a way to bypass this problem, and is also easy to implement.

The key is to programmatically compute where you are in the page, and how much space will need the footer, so you can move it down or eventually create a new page.

So, here the steps to accomplish that:
  1. Create a programmable section in the report to act as your page footer. Place in this programmable section all the controls that you want to render as the last page footer
  2. Create an empty footer section below the body that fetch your report data, and place an empy "Static text control" inside this footer (otherwise nothing will be rendered)
  3.  Override the method executeSection of the footer with the code below

 public void executeSection()  
   int pageHeight, currentPos, i;  
     pageHeight = element.mm100PageHeight();  
     currentPos = element.currentYmm100();  
     if(pageHeight < currentPos + ProgrammableSection.height100mm())  
     element.gotoYmm100(pageHeight - ProgrammableSection.height100mm());  

What I'm doing here is, if I ended up printing report data (in this case CustTable is empty) I compute the page height, where I am in the page, and how much space will need the footer.

Then you can print the footer in the proper position, or previously go to a new page if the space needed is not sufficient.

HERE  attached you find an XPO with a sample report

P.S.: My colleagues says that this problem belong also to SSRS reporting on AX 2012. I haven't seen it yet there, if you find a solution feel free to drop a line!

No comments: