These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Add New Page on the Fly Using JavaScript

lntucker1
Registered: Apr 30 2008
Posts: 8

I am new to LiveCycle and PDF creation, and I am wondering if I can create a new copy of an exisiting page and insert it into the PDF.

I have added a button to the page and inserted the following code (which I found in a help file):

----- form1.MySubForm.Button1::click: - (JavaScript, client) ---------------------------

methods.MySubForm.instanceManager.addInstance(1);

I am not getting any errors, but nothing happend when I click the button either!

Any information would be greatly appreciated - thanks in advance.

Lisa

My Product Information:
LiveCycle Designer, Windows
StevenD
Registered: Oct 6 2006
Posts: 368
Let's try this. First make sure your form is saved as a dynamic for so it can change as you add or subtract data or elements to the document. Next make sure the sub form is set to repeat for each data item. You do this by selecting the sub form and selecting the Binding tab in the Object pallet and checking the box that says "Repeat Subform for each Data Item". The script in your button is almost right. Here is the script I used in my test document. I just left off the word methods.

MainPageSF.instanceManager.addInstance(1);

"MainPageSF" is how I usually name the subform for the main page. Now when you click the button a new instance of the page subform will be added after the first instance and since it bigger than what will fit on the page a new page is added so now there are two page in the document.

StevenD

lntucker1
Registered: Apr 30 2008
Posts: 8
Dear StevenD,

I am in love!!! Thanks so much for your help with this...it is greatly appreciated!

Lisa
Jeffk
Registered: Jun 28 2010
Posts: 6
Thanks for the guidance Steven. I was hoping you (or any other experts out there) could help with the next step. I am using the add instance just like you suggested, but I want it to start on a new page.

I have a 'add page' button at the end of a form and when it's clicked, the instance is added, and tries to put a few lines on page 1 below my button, then wraps around to a new page. The form I am adding instances for must be able to break between sections.

I was hoping to add a line in the command just above the add instance line that would force a new page break. I've been unsuccessful with this and any variations like it:

Pg1.break.after = "pageArea";
Pg1.instanceManager.addInstance(1);

(and on a weird side note, this code works when using the form in Reader, but not when used from Acrobat. it says there is a syntax error. other than adding "xfa" in front of the commands, which doesn't work, i'm clueluess)

Anyone have any suggestions. Thanks so much!
StevenD
Registered: Oct 6 2006
Posts: 368
You should be able to specify via the UI that a field or subform will not break so when it gets to tall to fit on the page it will move to the next page as a unit.

StevenD

Jeffk
Registered: Jun 28 2010
Posts: 6
Understood, but thats the tricky part lol. I want my subform/form to be able to break EXCEPT when the new button is pushed and the new instance is thrown to the new page. Basically I have a one page form that I want to be expandable to a page and a half for example. The new instance button would then be on the middle of page 2. When clicked, I would like the new instance to start on page 3 rather than filling the bottom half of page 2 first. If that doesn't make sense, let me know. Thanks for the quick response!
StevenD
Registered: Oct 6 2006
Posts: 368
Maybe this is where a conditional break would help. I admit that I don't know how to set up a conditional break. I would hope someone else following this thread would be able to help explain how to set one up. I have read about them but have been able to understand them.

StevenD

Jeffk
Registered: Jun 28 2010
Posts: 6
I figured it out. For those of you who may have trouble with this, I stopped trying to do the page break altogether and just left the instance manager do its thing. I just told the subform to "Keep with Next" on the Pagination tab in the Object palette. This way, when the instance manager creates a 'copy' of my first page, the first subform that it lays down is kept with the next group and starts on a subsequent page.

I tried this originally for the whole page and it created a blank page where I didn't want one. The solution was to select this option for the subform, not the page itself. Thanks for your help though Steven!