Additional Blogs by Members
Showing results for 
Search instead for 
Did you mean: 
In this blog I am going to explain a solution to a very peculiar case of page break in Adobe forms that I came across in a project. Our first idea was to use conditional break which didn't work somehow. And so I took alternative approach explained here.
So here goes the problem: My client was printing a position description form in adobe which had multiple sections each of which could take any amount of space. First section was a header section with fixed length followed by variable length sections. The problem was to position those sections based on their length which was a run time factor. In short, these sections should print in such a way that if a particular section cannot be accommodated in the current page then it should start from next page.
Let me explain with examples by breaking this issue in 3 scenarios.
Scenario 1: Since section 1 is small enough to be accommodated in page one, it is printed in page 1. Section 2 then begins from page 2.
Scenario 2: Since section 1 is too large to be accommodated in page 1 but smaller than one full page, it gets printed in page 2 followed by section 2.
Scenario 3: Since section 1 is very large with its content spanning over more than one full page, it doesn't move to next page and instead beings from page 1 itself. Section 2 then follows.
First idea (failed attempt): My first attempt was to use conditional break. But it didn't work for some reason which is still unknown (
Alternative solution: The solution that finally worked doesn't make use of conditional break and instead use 'Page break within content' option with some code trick.
When 'Page break within content' option in subform is unchecked, the system tries to put all the content of subform in one page. So if a content is unable to fit in current page, it moves to the next page. So this should handle scenarios 1 and 2 mentioned above. However, this creates a problem for scenario 3 in which it leads to truncation of data because of the length of data being greater than one full page. To handle this situation, I created 2 subforms for each section. One with page break option selected and other without it. Now I had to build a logic which should make the appropriate subform visible and hide the other. Here is the logic for that:
Step 1. Find number of pages the content spans.
Step 2. Calculate the length of content. If the content is spread over two pages, length should be calculated from each page.
Step 3. IF LENGTH < 250 (avg. length of content which can be accommodated in one page) AND Number of PAGESPAN < 3
               { Display subform with page break option checked. }
               { Display subform with page break option unchecked. }
For a particular subform, spanning over 3 or more pages guarantees that the content cannot be accommodated in one page, the length calculation is done for maximum of 2 pages.
I have created a sample form with three sections and a driver program to explain this. The actual code in the form looks like this:
var a = xfa.layout.pageSpan(SF2.TextField2);
if (a == 2)
var b = xfa.layout.h(SF2.TextField2,"mm",0) + xfa.layout.h(SF2.TextField2,"mm",1);
else if(a == 1)
var b = xfa.layout.h(data.MainSF.sf12.SF2.TextField2,"mm");
if ((b < 250) & (a < 3))
data.MainSF.sf12.SF2.presence = "hidden";
data.MainSF.sf12.SF3.presence = "hidden";
After this logic, it is important to relayout the form to accommodate these changes. Otherwise, it will create blank spaces in the form arising out of subforms hiding. Relayout removes these subform completely from the final form.
Using the driver program, one can try out different length of text (through 'Repetition of String' screen field) in each section and see the form behavior:
Here are the form & interface xml download with driver program dump.
I hope this would help you in your similar requirements. Thanks for reading!!!
PS: This is my first experiment with Blogs. So excuse me if it is ill-written :smile: