Skip to main content
Inspiring
November 10, 2023
Question

How to add pages conditionally to a checkbox being checked ?

  • November 10, 2023
  • 1 reply
  • 3411 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.

Thom Parker
Community Expert
Community Expert
November 10, 2023

Ah okay, I understand, but in my case it'll be hard, because the two checkboxes that add pages are on two pages that are visible when the document opens and it would be inadequate to put a button or a checkbox on the first one, so that the second page with the checkbox that add pages appear depending of the context.


Please explain exactly (and simply), how the spawned pages are placed. 

 

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