Skip to main content
Inspiring
October 6, 2023
Answered

Button to show/ hide page templates

  • October 6, 2023
  • 2 replies
  • 8666 views

I have a check box button on page 1.  The following code works to show/hide page 2 .  Click the button, show page 2.  Unclick the button, hide page 2.

 

However, it gives me a "bad parameter" despite working.  Any ideas?

 

if(event.target.value!="Off")
{this.getTemplate("2" ).hidden=false;}
else
{this.getTemplate("2" ).hidden=true;}

This topic has been closed for replies.
Correct answer Thom Parker

It has two pages.  First page is always visible.  2nd page is what the button will show/hide.  Button is on page 1.

How do I set target page number?

 


Ok the target page isn't set. That is the source of the error.   Page numbers in the Acrobat JavaScript model are zero based. Page #1 is 0, and Page #2 is 1;

 

Use this code:

if(event.target.value!="Off")
{this.getTemplate("2" ).spawn(1, false, false);}
else
{this.deletePages(1);}

 

 

2 replies

Thom Parker
Adobe Expert
October 6, 2023

Is the Template named "2"?  If not I don't see how the code could work. Also, unhiding a template always places the page at the end of the document. You can't specify the page where it will appear. 

 

Also, hiding and showing a template will not work in Reader. The correct way to use a template is to "spawn" it. 

This thread provides a checkbox spawn solution:

https://community.adobe.com/t5/acrobat-discussions/spawn-templates-after-a-specific-page-with-checkboxes/m-p/14137819#M432760

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
MBChelsAuthor
Inspiring
October 6, 2023

I tried the code from the thread you provided and nothing happened

if(event.target.value!="Off")
{this.getTemplate("2" ).spawn(nTargetPageNumber, false, false);}
else
{this.deletePages(nTargetPageNumber);}

 

Thom Parker
Adobe Expert
October 13, 2023

I recreated the entire document and it still gave me bad parameter error....very strange


What is your process for creating the document?

Can you post the PDF?

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
MBChelsAuthor
Inspiring
October 6, 2023

Also, this bad parameter error prevents me from saving this document.