Skip to main content
Christopher Teacher
Known Participant
January 6, 2023
Question

Making buttons to add and REMOVE optional pages of a form

  • January 6, 2023
  • 1 reply
  • 549 views

I am creating a form that has some pages which are optional based on user's needs.  I've figured out how to place buttons that will spawn those additional pages based on embedded templates; however, I also want to have buttons that will hide said pages again in case someone adds one in error.  The script I used in the buttons to add the pages is this:

 

var a = this.getTemplate ("Interview notes");
a.spawn();

 

I tried using this script in a "Remove Page" button... 

 

var currentPageNumber = this.pageNum;
this.deletePages({nStart: currentPageNumber, nEnd: currentPageNumber});
 
...but unfortunately it deletes the whole page template meaning that the add page button no longer does anything within that version of the file.  
 
I also tried the following:
 
Add page- 
 
var t = this.getTemplate ("Interview notes");
t.hidden=false
 
And this for the remove page button:
 
var t = this.getTemplate("Interview notes");
t.hidden=true  
 
This worked beautifully... until I opened the file in Acrobat Reader rather than Pro, and then it didn't work at all (all template pages were visible all the time).  
 
Basically, I need something that does the opposite of the "spawn" command, and gets that template back to a hidden state without removing it entirely.  
 
Thank you!
This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
January 6, 2023

As you've seen. A field script in Reader can delete, but not hide a template page. So the correct method for using a page template is to always hide the template up front (at design time). If a template page is needed in the initial document, then it should also be spawned up front. Then a script can be used to delete it. 

Again, the correct method for using a page template is to spawn and delete pages from the original template, which is hidden. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Christopher Teacher
Known Participant
January 6, 2023

So, no way to re-hide it after it has spawned?

Thom Parker
Community Expert
Community Expert
January 6, 2023

No, Template pages are spawned and deleted. Never hidden. The hidden attribute for the template is a convience for form design. It is not used at runtime. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often