Skip to main content
Inspiring
November 10, 2023
Question

How to add pages conditionally to a checkbox being checked ?

  • November 10, 2023
  • 1 reply
  • 3461 views

Hi,

I have a pdf form document in which there's checkboxes that add a page after a certain page based by their number in the order of appearance. My code is : 

 

var a = this.getTemplate ("AddPage11");

a.spawn(3, false, false);

this.pageNum = 1

 

And it works. But I have several checkboxes like this and so for the subsequent checkboxes that add pages, the order of appearance is conditional to the choice that the user made by clicking on a prior checkbox. Is there a way that a javascript can add pages conditionally to a prior checkbox adding pages being checked ?

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
November 10, 2023

You could enable/disable or show/hide the checkboxes based on previous checkbox values. 

Are the pages also deleted if the checkbox is turned off? 

If there are several templates and associated checkboxes, then this process of spawning and deleting will need to be managed carefully. For example after two pages are spawned, the first checkbox may need to be blocked so the first page is not deleted before the second page. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
November 10, 2023

No, the pages are neither deleted, nor hidden. In fact, when you click on a check box, it creates a template page saved with the function Organize Pages. However, if I click on the checkbox and it creates a page after the first page, every other page that were already visible on the document move from one page, because the new page is the second page now. If on page 4, there's a checkbox to add a page after page 7, page 7 is now page 8, because of the page that got added, so the page that was added after page 7 is now shifted.

Inspiring
November 15, 2023

Now, do you want to stop Page 4 from being spawned if Page 3 hasn't been spawned? Or can page 4 be spawned first, then page 3 will be inserted before Page 4?  And what happens if the user goes back and checks "No" for one of the options?  Does the associated page stay in place? 

 

When there is a complex arrangment of elements that are controled though programming (any kind of element, not just pages) then it is necessary to have a complete description of the behavior. 

 


Actually I found a way thank you !