Hello Piyush,
I will take a simple example. Let us consider that if you stretch the content area till the end, then maximum of 12 rows will occupy in a single page.
For now, let us consider that only a maximum of 12 rows will fit in a single page. I know the footer mentioned by you in the question is 10-12 rows in height. But let us move in a simple way.
First you have to check that how many rows are equivalent to 1 footer. For now, let us consider that only a maximum of 12 rows will fit in a single page. And the Footer is exactly 2 rows in height.
Now you need 2 master pages.
1st - master page---> Overlap the Footer on the Content area.
2nd - master page---> Create a new page with footer at the bottom.
Let us look at some of the scenarios below. This is very important because our next design is very much based on this.
1) 2 rows are equivalent to 1 footer. So 12 – 2 = 10 rows. So if there are less than or equal to 10 rows, then only 1 page will be printed.
2) If there are 11 rows, then 2 pages will be printed. 11 rows in 1st page and only the header and footer in 2nd page.
3) If there are 12 rows, then 2 pages will be printed. 12 rows in 1st page and only the header and footer in 2nd page.
4) If there are 24 rows, then 3 pages will be printed. 12 rows in 1st page, next 12 in 2nd page, and only the header and footer in 3rd page.
5) If there are 36 rows, then 4 pages will be printed. 12 rows in 1st page, next 12 in 2nd page, next 12 in 3rd page and only the header and footer in 4th page.
From point 2,3,4 and 5 we can conclude that the new master page will be triggered when the number of rows in the table is greater than 10 OR when the number of rows in the table is exactly divisible by 12.
6) If there are 23 records, then 3 pages will be printed.12 rows in 1st page, 11 in 2nd page, and only the header and footer in 3rd page.
7) If there are 35 records, then 4 pages will be printed.12 rows in 1st page, 12 in 2nd page, 11 in 3rd page and only the header and footer in 4th page.
From point 6 and 7, we can conclude that the new master page will be triggered when the number of rows divided by 12 gives the remainder of 11. i.e number of rows % 12 should be 11.
6) If there are 15 rows, then 2 pages will be printed. 12 rows in 1st page, and the header, the rest of the 3 rows and footer in 2nd page.
7) If there are 36 rows, then 4 pages will be printed. 12 rows in 1st page, 12 in 2nd page, 12 in 3rd page and only the header and footer in 4th page.
So if you look at the pattern here, a new page with only the header and footer should be triggered only when the number of rows in the table is greater than 10 and either the number of rows in the table is exactly divisible by 12 or number of rows % 12 should be 11. i.e By using Modulus Operation, number of rows % 12 should give you zero or number of rows % 12 should give 11. In rest of the cases, only the 1st master page will be used.
Case 1 - If the rows and the footer comes in same page.
Now you have to take care that the footer should always be bottom aligned in the last page of 1st master page.. So for this you have to design the footer in the 1st master page. So overlap the Footer on the Content area. Later we will see how to show the footer only once in the last page.
Case 2 - If the rows end exactly or almost at the end of content area with no space available for a footer in 1st master page.
That's why you have to create new master page (Master Page 2) and then design the footer (bottom aligned) in this page. Now create a dummy sub form in the design view of the Page2. If you don't create a dummy sub form, then the 2nd page will never trigger. This is the key to triggering the 2nd master page.
How to determine if it is a Case 1 or Case 2 ??
2 rows are equivalent to 1 footer.
So 12 – 2 = 10 rows.
So Case 2 will only occur if number of rows is greater than 10 and if the total number of rows is exactly divisible by 12 or number of rows % 12 should give 11.
Now in the driver program, determine the number of rows in the table. Then set the flag if the CASE 2 is occurring.
So to determine whether it is CASE1 or CASE2, write the below code in driver program.
DATA: flag TYPE flag,
num TYPE i.
DESCRIBE li_tab LINES num.
IF ( num GT 10 AND ( num MOD 12 = 0 OR num MOD 12 = 11 )).
Flag = ‘X’.
ENDIF.
If FLAG contains blank, it is Case 1.
If FLAG contains “X”, it is Case 2.
Preventing Conflicts between Case 1 and Case 2
If Flag contains Blank, then it’s a first case. So footer from 1st Master page will appear only at the end of 1st master page. So you have to always hide the entire 2nd master page.
If Flag contains “X”, then it’s a second case. So footer from 2nd Master page will appear. So in this case you have to always hide the Footer of 1st master page.
For Case 1 - Write the below JavaScript code in the Ready Layout event of Footer sub form of 1st Master Page
// If CASE 2, then hide the footer of 1st master page
If ( data.FLAG.rawvalue != null )
{
This.presence = “hidden”;
}
Else
// If CASE 1, then show the footer only at the end of 1st master page
{
If ( this.rawValue = xfa.layout.page(this) != xfa.layout.pageCount() )
{
This.presence = “hidden”;
}
}
What the above JavaScript basically does is that, it will check if it is case 2. If yes, it will hide the footer of 1st master page. Else it will check if it is case 1. If yes, it will show the footer only in last page of 1st master page.
For Case 2 - No need to write the JavaScript on Footer sub form of 2nd Master Page. Because anyways if FLAG is blank, we will hide the entire 2nd Master Page
Drag the FLAG variable in the layout under data node. Write the JavaScript on Dummy sub form in Initialize event as below.
// If FLAG is empty, then hide entire 2nd master page
If ( data.FLAG.rawvalue == null )
{
This.presence = “hidden”;
}
Note: The main idea over here is to get the exact height of the footer equivalent to number of rows. As you said that the footer is 10-12 rows in height, I would like to mention that please calculate the exact value of Footer. Either it should be 10 rows height or it should be 12 rows but not both. I have taken a simple example here. I hope it will be almost same in your case too. Just the numbers might be different. I know it is difficult initially and not to mention that this is all about Trial and Error method at first. Its a one time activity. If you do the calculations correctly first time, it will make your life easier.Yes I know that the solution given be me is not fully dynamic but I hope it will definitely help you.