cancel
Showing results for 
Search instead for 
Did you mean: 

Required Script for Adobe Form

Piyushmatrixs
Participant
0 Kudos

Hi experts,

    I required your urgent help for my development. I made a adobe form for customer ledger. Form is divided in 3 parts as shown in below image:


Header sub form will print on each page if form is more than one page. Then Body will grow to multiple page according data. Next is footer, it will print on last page (either last page is 1st or 4th page) positioned bottom. The problem is that in some situation. Like it prints Header, then prints body sub-form for open item. It grow according data. suppose that open item end on second page then footer should be placed on second page at bottom aligned. Footer sub-form is 2 inches( or 10-12 rows) in height. It should be checked that after end of body subform how much space is available. if there enough space for footer to be print then footer will print on same page other wise it will create one more page, at top of that page will print header sub-form and then at bottom aligned footer sub-form (there would be blank space between header and footer).

  How to do that. Your help would be appreciate.

Please reply asap.



Thanks and Regards

Piyush Kumar

Accepted Solutions (0)

Answers (6)

Answers (6)

pavan_prabhu
Active Participant
0 Kudos

Hello Piyush,

     I had provided you a solution. Is it working?

pavan_prabhu
Active Participant
0 Kudos

Hello Piyush,

     Each row in the table will occupy a single line or will it occupy multiple lines also??

Piyushmatrixs
Participant
0 Kudos

Hi Pavan,

  Each row in the table will occupy only a single line.

Regards

Piyush

pavan_prabhu
Active Participant
0 Kudos

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 12 rows, then 2 pages will be printed. 12 rows in 1st page and only the header and footer in 2nd page.

3) 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.

4) 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 and 4 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.

5) 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.

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 also 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 but its a one time activity. If you do the calculations correctly first time, it will make your life easier. Hope my solution will help you.

Piyushmatrixs
Participant
0 Kudos

Hi Pavan,

   Please see below snapshot and reply asap.

Thanks & Regards

Piyush

nsikka
Active Participant
0 Kudos

Hey,

It can be written in Master page initialize event.

Great explanation

Piyushmatrixs
Participant
0 Kudos

Hi Nitin,

  

    Pavan told that put the dummy subform in design view and write this script on that dummy subform in his explanation. I did the same.
     Problem:- I executed the program, footer and header are able to fit on first page with table data (table has 6 lines), so program must create only one page with header, table data and footer, but program is creating also one more page (second page in this case) with header and footer subform, while second page must be hidden.

  what is wrong?

Regards

Piyush

nsikka
Active Participant
0 Kudos

Well, it should ideally go to 2nd master page only when it overflows data.

I think page structuring is an issue here.

Your page structure should be -

Master page1

- Body Page (In the overflow condition you can mention Master page 2, so then when data overflow then it should use master page 2)

Master Page2

I think you have put in master page2 under Master page 1 itself or something like that.

Thank,

Nitin

pavan_prabhu
Active Participant
0 Kudos

Hello Piyush,

     You have to write this script on Design view of Page 2 because this sub form will be in design view itself and not in master page. The reason I told to put in design view is if you hide this sub form, the whole instance of Page 2 will not appear at all. So you will not get a blank page.

FLAG will be blank only if it is a CASE 1. So if this sub form is hidden successfully, then there will be nothing left to be shown in Content area of Page 2. So the 2nd Page which you designed will not appear at all in the PDF output.

Piyushmatrixs
Participant
0 Kudos

Hi Prabhu,

Thanks for your help. I wanted solution like that. I did the same as above, but there is a problem. Table data is has 5 lines. So it should generate only one page with header--body(table)---Footer. But it is creating 2 pages. First page contains Header--Body(Table)---Footer   and  second page contains Header and footer.

    Why is it creating additional page?

Regards

Piyush

former_member221372
Participant
0 Kudos

Hi Piyush,

Create a sub form for footer just below the Body of Items Sub Form.In Footer Sub Form ,we have check box ( Allow Page Breaks ) as shown below.

Cheers,

Bharath

Piyushmatrixs
Participant
0 Kudos

Hi,

   First thing that Footer sub-form already enabled check box of "Allow Page break...".  Body Page has flowed property. So if keep footer sub-form at the place suggested by you, and table have only 5-10 records, then it will print footer sub form just below closing balance subform, not at bottom. It would be 1-1.5 inches above bottom margin, while I have to print it bottom aligned.

Regards

Piyush

nsikka
Active Participant
0 Kudos

Hi Piyush,

Try out this way :

- Put the footer by adjusting the content area.

- Display footer only when it is last page or first page using this script

I will check if current page is last page then only it will display the footer.

Piyushmatrixs
Participant
0 Kudos

Hi Nitin,

  I have done this(script) already. I want to know that is there any way by which I can do like this:

1).  I can count/calculate space in inches or in line(row) available  at bottom after printing sub-forms placed on design view.

2). If step 1 done, after that can I make a condition like below:

                 if rest_of_row(space)  < 5 then

                         create one more page and print footer subform with Header sub-form.

                 else.

                         print footer on same page.

See page structure and output for a better understanding.

structure:

Current Output :

Regards

Piyush

nsikka
Active Participant
0 Kudos

I Think you can put the footer in the master page instead of keeping in design view. So reduce the content area and put the footer content in the bottom in a subform and write this script on that subform.

You need not calculate number of rows to print the subform

Piyushmatrixs
Participant
0 Kudos

Hi,

    I have already done same (footer in master page).  But if I shall reduce the content area for footer, and if content (of table 2) overflows and data creates second or third page, then it will keep empty space on each previous pages (on first page, second page.....) equal to footer sub-form. I can not leave these empty space by reducing content area.

   Any other suggestion?

Regards

Piyush

nsikka
Active Participant
0 Kudos

Ok, Do one thing. .. First check approx how many entries are coming on one page say for example 10.

Now in the print program check the total number of entries in the table which is getting printed on the form... for example it is 95

You can calculate the number of pages it will print i.e. 95/10 = 9.5. It means you have to print footer on 10th page.

So you can pass a variable as importing parameter and then check it in the script code to print the footer.

Piyushmatrixs
Participant
0 Kudos

Hi,

     Suppose 10 entries can be print between header and footer sub-form. And  There is 12 entries for printing. At present when I run the program, It print header then print the all 12 entries at same page because content area has space upto bottom margin (I can't reduce content area for reserving space for footer ), and also print footer sub-form at same page, due to this footer sub-form overlap on two entries of table.

    Can you tell me that how shall I print the 12 entries at first page and break the page after 12 entries (because footer will not fit at same page) and will call next page (second page) & print footer sub-form at bottom margin?

Regards

Piyush

nsikka
Active Participant
0 Kudos

Hi Piyush,

WHat you can you is, select that table and go to pagination tab as shown above.

Select the page where you want to go in case of overflow.

And in the traailer select the footer subform.

So, it will print the footer subform after table printing is finished.

Piyushmatrixs
Participant
0 Kudos

Hi,

   Please have a look for all three condition.

--------------------------------------------------------------------------------------------------------------------------------------------

(Note : For footer, we can not reserve space.  If header and footer are on same page,then It means table have only 10 rows. if table have less or more than 10 rows then:

---------------------------------------------------------------------------------------------------------------------------------------------

1).  If table has only 2 or 3 entry then Page would be like this:

------------------------------------------------------------------------------------------------------

2). If table has upto 10 entries then page would be like this:

-----------------------------------------------------------------------------------------------------

3).  If Table has 11-20 entries then pages would be like this (footer aligned at bottom margin,). like if table has 12 entries then (tell how to set or code for calling second page like below (no footer subform break within content))

I hope that now it is more understandable. Now tell what should I do?

Regards

Piyush

nsikka
Active Participant
0 Kudos

Ok.. You can do like this..

Go to master page and put the footer subform over content area. Do not reduce the content area to fit the footer. Just overlap like this :

And write the script to display footer subform on last page. So this way you will not consume the space on every page and display the footer on last page only and in the bottom margin

Thanks,

Nitin

Piyushmatrixs
Participant
0 Kudos

Hi,

   Thanks for reply. I have already done this what you are saying. I want to bring your attention on above condition. What you told to do, is good and will work correctly with first and second condition. But when we run it with third condition then :

     If table have 12 entries.

         It will print all twelve entries on first page.

             and it will also print footer on that first page and footer also will overlap over 2 rows of table.

                  In this condition I want to do that program call and generate second page and place the footer on second page. It means if tables have 12 entries then program will create 2 page, first page contain Header then 12 rows of table(no footer on this page) and second page will contain Header at top and footer at bottom margin(no table and there would empty space between header and footer).

  How to do this?

Regards

Piyush

Former Member
0 Kudos

Hi Piyush,

I can see one solution here. Please mention if it is not meeting your requirement.

We can reserved the space for the footer for each page. Footer will be hidden for the all pages except last page. In the last page it will be visible.

Problem: In each page the footer space will be empty. This is ok if the footer takes less height.

Thanks,

Krishna.

Piyushmatrixs
Participant
0 Kudos

Hi Krishna,

      Yes, you are right. We can reserve space for footer, but the problem would be same you mention. I am sorry to say that it will not fulfill my requirement.

   I think that space could be reserv by a adjusting content area. If you solution is other than this then your solution may help me.

Regards

Piyush Kumar

sandeep_katoch
Contributor
0 Kudos


Hi Piyish,

you need not to write any script. Subfomr properties will help.

Just check the page break property and make it not allowed. It will automatically take care of your requirement

Regards,

Sandeep Katoch