• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Making buttons to add and REMOVE optional pages of a form

New Here ,
Jan 06, 2023 Jan 06, 2023

Copy link to clipboard

Copied

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!
TOPICS
JavaScript , PDF forms

Views

267

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2023 Jan 06, 2023

Copy link to clipboard

Copied

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 06, 2023 Jan 06, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2023 Jan 06, 2023

Copy link to clipboard

Copied

LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines