Skip to main content
Participant
October 16, 2024
Question

Hide/reveal pages based on the one checkbox selection

  • October 16, 2024
  • 2 replies
  • 541 views

Good day all!

Need help. I have a 3 page PDF document and if one of the checkboxes "chkHidePages" on first page is selected, last 2 pages of the PDF are not needed and i'd like them to disappear. If checkbox "chkHidePages" is unslected, then I'd need those 2 last pages to reappear. Export value is at "Yes". Mouse Up. Run Javascript.

I tried this code below and it does not work. Thanks in advance. Pls help: 

 

// Get the checkbox field by its name

var checkbox = this.getField("chkHidePages"); // Make sure the name matches exactly

 

// Check the value of the checkbox field

if (checkbox.value === "Yes") {

    // Hide pages 2 and 3 (page indexes 1 and 2)

    this.setPageVisibility(1, false); // Page 2 (index 1)

    this.setPageVisibility(2, false); // Page 3 (index 2)

    app.alert("Pages 2 and 3 have been hidden."); // Debugging alert to confirm the action

} else {

    // Show pages 2 and 3

    this.setPageVisibility(1, true); // Page 2 (index 1)

    this.setPageVisibility(2, true); // Page 3 (index 2)

    app.alert("Pages 2 and 3 are visible again."); // Debugging alert to confirm the action

}

This topic has been closed for replies.

2 replies

PDF Automation Station
Community Expert
Community Expert
October 16, 2024
Thom Parker
Community Expert
Community Expert
October 16, 2024

There is no such function as "setPageVisibility".  In fact, pages cannot be hidden and shown. But you can create this effect by using a page template.  Templated pages are "spawned" and "deleted". 

You'll find lots of posts about page templates on this forum, and here is the entry in the Acrobat JavaScript Reference:

 

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#template

 

Also, in the "if" use this code:  (assuming this is a mouseUp script on the checkbox);

if (event.target.value == "Yes") {

 

 

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