Skip to Content
Author's profile photo Bhaskar Tripathi

Curious Case of Page Break in Adobe Forms :)

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.
Examples.jpg
First idea (failed attempt): My first attempt was to use conditional break. But it didn’t work for some reason which is still unknown (http://scn.sap.com/thread/3390883).
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.
Allow Page Break Option.jpg
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. }
            ELSE.
               { 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";
}
else
{
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.
xfa.layout.relayout();
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:
Driver Program.JPG
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 🙂

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Vaibhav Tiwari
      Vaibhav Tiwari

      Really a good info and quite helpful for those who are facing this issue in such requirement.

      Author's profile photo Bhaskar Tripathi
      Bhaskar Tripathi
      Blog Post Author

      Thanks Vaibhav! 🙂

      Author's profile photo Dominik Tospann
      Dominik Tospann

      Hello Bhaskar,

      thank you very very much for sharing this...my problem was driving me nuts! I was missing a simple command I didn´t know before (xfa.layout.relayout()).

      Solved it for me!

      Thanks!

      Author's profile photo kalyanaviswakanth muppa
      kalyanaviswakanth muppa

      Hi,

      Nice blog!! I have a question here

      When I do it in a loop it works for the first line item only. Do i need to do something here?

       

      Regards,

      Kalyan

      Author's profile photo Bhaskar Tripathi
      Bhaskar Tripathi
      Blog Post Author

      Thanks! Which loop? I am not clear about your issue.

       

      BR,

      Bhaskar