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

How to add pages conditionally to a checkbox being checked ?

Explorer ,
Nov 10, 2023 Nov 10, 2023

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 ?

TOPICS
JavaScript , PDF forms
3.0K
Translate
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 ,
Nov 10, 2023 Nov 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
Explorer ,
Nov 10, 2023 Nov 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.

Translate
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 ,
Nov 10, 2023 Nov 10, 2023

You misunderstand me.

If it is necessary to control the order of page spawning, then one strategy is to hide the checkboxes that trigger the spawn of a particular page so they cannot be clicked until conditions are right for that to happen. 

 

Alternatively, if the goal is to place the spawned page at a particular location (which may change because of other spawned pages) then markers can be placed on the existing pages to identify the spawn locations.  The best option for a marker is to use a form field.  For example, if the spawned page is to be placed on the page after the page with the checkbox that spawns it, then the checkbox itself is the marker.  

this.getTemplate ("AddPage11").spawn(event.target.page+1, false, false);

 

Or if the target page is somewhere else, a hidden button field could be placed on the page after which the template is to be placed. 

 

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

Translate
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
Explorer ,
Nov 10, 2023 Nov 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.

Translate
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 ,
Nov 10, 2023 Nov 10, 2023

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

 

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

Translate
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
Explorer ,
Nov 10, 2023 Nov 10, 2023
 
Translate
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 ,
Nov 10, 2023 Nov 10, 2023

That doesn't tell me anything.

Are the pages supposed to be added in a specific order? 

Are they always added to the end of the document? 

Are there going to be more than just these 2 templates?

 

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

Translate
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
Explorer ,
Nov 10, 2023 Nov 10, 2023

The pages are as follows : Page 1 - 1. informations; Page 2 - 1.2. Informations on the delivery compagny; Page 3 - 2. Product; Page 4 - Other Product. There's gonna be other pages of products very similar to page 4 after page 4. Page 4 should always come after page 3, and page 2 should always come after page 1. However, Page 2 is not necessarly going to be present everytime this form is completed.

Translate
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 ,
Nov 10, 2023 Nov 10, 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. 

 

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

Translate
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
Explorer ,
Nov 15, 2023 Nov 15, 2023
LATEST

Actually I found a way thank you !

Translate
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