Highlighted

Use action button to add a specific template depending on a check box

Community Beginner ,
Oct 01, 2020

Copy link to clipboard

Copied

I have 3 check boxes (let's say A, B and C). Whenever one of the is checked, a certain text field appears.

 

Separately, I have a button which should add a new page based on a template. This is the script I am using:

var a = this.getTemplate("Template A");
a.spawn();

 

Is there a way to modify the script such that the template added depends on the check box which has been ticked before (A, B or C)? so if check box A was ticked, the button will add a Template A page, but if check box B was checked, the same button will add a Template B page?

 

Thank you!

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

+++EDITED REPLY   edited some typos and rephrased some of the explations

 

Yes, deifinetly. If you're using mutually exclusive radio buttons that works even better (in my opinion), and also execute the spawning of templates without the need of a button for that.

 

Since you can incorporate the  desired spawining script to add a template as a JavaScript action in the radio button itself (which pretty much acts exactly as a mouse up action as if it was executed from a button), I would use a button just to reset the checked or unchecked state of your radio button group(s) instead, 

 

Also, you may want to download the Adobe Acrobat DC SDK Acrobat Templates, 
Developing Acrobat® Applications Using JavaScript™,  see this section "Dynamic form field generation"  starting in Page  151  through 153.  Specifically see the section "Template syntax and usage".  It  explains thoroughly with script examples how to handle the generation of page templates based on specific pages, renaming fields and autopopulating the new renamed fields,  and how to append them onto the document with a specific page order using the spawn method to avoid file overinflation. 

 

Here's an example of the spawining template script found in page 152 of the reference above that you can modify to suit your needs:

 

 

 

 

*/ In this next example, we will retrieve the template named myTemplate, overlay it onto pages 5 through 10 (bOverlay will be true), and use the same field names on each page (bRename will be false): */

// Obtain the template name "myTemplate":
var t = this.getTemplate("myTemplate");

// Prevent file size inflation:
var XO = t.spawn(5, true, false);

// Spawn the remaining pages:
for (var i = 6; i <= 10; i++)
t.spawn(i, true, false, XO);

 

 

 

 

Also, see ACP Thom  Parker's comment about handling template on this thread: 

 

 

As far as the radio buttons are concerned this is how I'm using it on my end:

 

  • Created a mutually exclusive radio button group named "Radio Button" and set the export values as "Template A", "Template B", Template C".
  • Created my template pages using the Organize  Pages tool and set these templates as hidden ("Template A, Template B, and Template C)
  • Created three text fields named them "myTextFieldA", "myTextFieldB", "myTextFieldC" respectively
  • Created a button to reset the Radio Button group (default state for my radio buttons is unchecked)

 

Use this script on first Radio Button (with export value "Template A"):

 

 

 

 

this.getField("myTextFieldA").display = display.visible;
this.getField("myTextFieldB").display = display.hidden;
this.getField("myTextFieldC").display = display.hidden;

this.resetForm(["myTextFieldB","myTextFieldC"]);

/// Obtain the template name "myTemplate":
var A = this.getTemplate("Template A");

// Prevent file size inflation; overlay the template on the last page of the document:
var XO = A.spawn(-1, true, false);

 

 

 

 

Use  this script on second Radio Button (with export value "Template B"):

 

 

 

 

this.getField("myTextFieldA").display = display.hidden;
this.getField("myTextFieldB").display = display.visible;
this.getField("myTextFieldC").display = display.hidden;

this.resetForm(["myTextFieldA","myTextFieldC"]);


//Delete the last page from the document. The (0-based) page number of the last page in the document is this.numPages - 1
this.deletePages({ nStart: this.numPages - 1 });

/// Obtain the template name "myTemplate":
var B = this.getTemplate("Template B");

// Prevent file size inflation; overlay the new template on the last page :
var XO = B.spawn(-1, true, false);

 

 

 

 

 

Then place this script on third Radio Button (with export value "Template C"):

 

 

 

 

this.getField("myTextFieldA").display = display.hidden;
this.getField("myTextFieldB").display = display.hidden;
this.getField("myTextFieldC").display = display.visible;

this.resetForm(["myTextFieldA","myTextFieldB"]);

//Delete the last page from the document. The (0-based) page number of the last page in the document is this.numPages - 1
this.deletePages({ nStart: this.numPages - 1 });

/// Obtain the template name "myTemplate":
var C = this.getTemplate("Template C");

// Prevent file size inflation; overlay the template on last page:
var XO = C.spawn(-1, true, false);

 

 

 

 

As you can see, selecting radio button with export value "Template A" will spawn my hidden page labeled "Template A" and overlay it on the last page of my PDF.

 

Clicking on the subsequent radio button will delete that last page and replace it by overlaying the corresponding template based on the script.

 

Last clicking on the reset button resets all radio button to its default state which is unchecked.

TOPICS
PDF forms

Views

110

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Use action button to add a specific template depending on a check box

Community Beginner ,
Oct 01, 2020

Copy link to clipboard

Copied

I have 3 check boxes (let's say A, B and C). Whenever one of the is checked, a certain text field appears.

 

Separately, I have a button which should add a new page based on a template. This is the script I am using:

var a = this.getTemplate("Template A");
a.spawn();

 

Is there a way to modify the script such that the template added depends on the check box which has been ticked before (A, B or C)? so if check box A was ticked, the button will add a Template A page, but if check box B was checked, the same button will add a Template B page?

 

Thank you!

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

+++EDITED REPLY   edited some typos and rephrased some of the explations

 

Yes, deifinetly. If you're using mutually exclusive radio buttons that works even better (in my opinion), and also execute the spawning of templates without the need of a button for that.

 

Since you can incorporate the  desired spawining script to add a template as a JavaScript action in the radio button itself (which pretty much acts exactly as a mouse up action as if it was executed from a button), I would use a button just to reset the checked or unchecked state of your radio button group(s) instead, 

 

Also, you may want to download the Adobe Acrobat DC SDK Acrobat Templates, 
Developing Acrobat® Applications Using JavaScript™,  see this section "Dynamic form field generation"  starting in Page  151  through 153.  Specifically see the section "Template syntax and usage".  It  explains thoroughly with script examples how to handle the generation of page templates based on specific pages, renaming fields and autopopulating the new renamed fields,  and how to append them onto the document with a specific page order using the spawn method to avoid file overinflation. 

 

Here's an example of the spawining template script found in page 152 of the reference above that you can modify to suit your needs:

 

 

 

 

*/ In this next example, we will retrieve the template named myTemplate, overlay it onto pages 5 through 10 (bOverlay will be true), and use the same field names on each page (bRename will be false): */

// Obtain the template name "myTemplate":
var t = this.getTemplate("myTemplate");

// Prevent file size inflation:
var XO = t.spawn(5, true, false);

// Spawn the remaining pages:
for (var i = 6; i <= 10; i++)
t.spawn(i, true, false, XO);

 

 

 

 

Also, see ACP Thom  Parker's comment about handling template on this thread: 

 

 

As far as the radio buttons are concerned this is how I'm using it on my end:

 

  • Created a mutually exclusive radio button group named "Radio Button" and set the export values as "Template A", "Template B", Template C".
  • Created my template pages using the Organize  Pages tool and set these templates as hidden ("Template A, Template B, and Template C)
  • Created three text fields named them "myTextFieldA", "myTextFieldB", "myTextFieldC" respectively
  • Created a button to reset the Radio Button group (default state for my radio buttons is unchecked)

 

Use this script on first Radio Button (with export value "Template A"):

 

 

 

 

this.getField("myTextFieldA").display = display.visible;
this.getField("myTextFieldB").display = display.hidden;
this.getField("myTextFieldC").display = display.hidden;

this.resetForm(["myTextFieldB","myTextFieldC"]);

/// Obtain the template name "myTemplate":
var A = this.getTemplate("Template A");

// Prevent file size inflation; overlay the template on the last page of the document:
var XO = A.spawn(-1, true, false);

 

 

 

 

Use  this script on second Radio Button (with export value "Template B"):

 

 

 

 

this.getField("myTextFieldA").display = display.hidden;
this.getField("myTextFieldB").display = display.visible;
this.getField("myTextFieldC").display = display.hidden;

this.resetForm(["myTextFieldA","myTextFieldC"]);


//Delete the last page from the document. The (0-based) page number of the last page in the document is this.numPages - 1
this.deletePages({ nStart: this.numPages - 1 });

/// Obtain the template name "myTemplate":
var B = this.getTemplate("Template B");

// Prevent file size inflation; overlay the new template on the last page :
var XO = B.spawn(-1, true, false);

 

 

 

 

 

Then place this script on third Radio Button (with export value "Template C"):

 

 

 

 

this.getField("myTextFieldA").display = display.hidden;
this.getField("myTextFieldB").display = display.hidden;
this.getField("myTextFieldC").display = display.visible;

this.resetForm(["myTextFieldA","myTextFieldB"]);

//Delete the last page from the document. The (0-based) page number of the last page in the document is this.numPages - 1
this.deletePages({ nStart: this.numPages - 1 });

/// Obtain the template name "myTemplate":
var C = this.getTemplate("Template C");

// Prevent file size inflation; overlay the template on last page:
var XO = C.spawn(-1, true, false);

 

 

 

 

As you can see, selecting radio button with export value "Template A" will spawn my hidden page labeled "Template A" and overlay it on the last page of my PDF.

 

Clicking on the subsequent radio button will delete that last page and replace it by overlaying the corresponding template based on the script.

 

Last clicking on the reset button resets all radio button to its default state which is unchecked.

TOPICS
PDF forms

Views

111

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 01, 2020 0
Adobe Community Professional ,
Oct 01, 2020

Copy link to clipboard

Copied

Are these checkboxes mutually exclusive or do you want to give the users the ability to check more than one checkbox?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 01, 2020 0
Community Beginner ,
Oct 01, 2020

Copy link to clipboard

Copied

They are mutually exclusive

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 01, 2020 0
Community Beginner ,
Oct 01, 2020

Copy link to clipboard

Copied

Or I could also use radio buttons to make sure only one of them is checked at a time

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 01, 2020 0
Adobe Community Professional ,
Oct 02, 2020

Copy link to clipboard

Copied

+++EDITED REPLY   edited some typos and rephrased some of the explations

 

Yes, deifinetly. If you're using mutually exclusive radio buttons that works even better (in my opinion), and also execute the spawning of templates without the need of a button for that.

 

Since you can incorporate the  desired spawining script to add a template as a JavaScript action in the radio button itself (which pretty much acts exactly as a mouse up action as if it was executed from a button), I would use a button just to reset the checked or unchecked state of your radio button group(s) instead, 

 

Also, you may want to download the Adobe Acrobat DC SDK Acrobat Templates, 
Developing Acrobat® Applications Using JavaScript™,  see this section "Dynamic form field generation"  starting in Page  151  through 153.  Specifically see the section "Template syntax and usage".  It  explains thoroughly with script examples how to handle the generation of page templates based on specific pages, renaming fields and autopopulating the new renamed fields,  and how to append them onto the document with a specific page order using the spawn method to avoid file overinflation. 

 

Here's an example of the spawining template script found in page 152 of the reference above that you can modify to suit your needs:

 

 

 

 

*/ In this next example, we will retrieve the template named myTemplate, overlay it onto pages 5 through 10 (bOverlay will be true), and use the same field names on each page (bRename will be false): */

// Obtain the template name "myTemplate":
var t = this.getTemplate("myTemplate");

// Prevent file size inflation:
var XO = t.spawn(5, true, false);

// Spawn the remaining pages:
for (var i = 6; i <= 10; i++)
t.spawn(i, true, false, XO);

 

 

 

 

Also, see ACP Thom  Parker's comment about handling template on this thread: 

 

 

As far as the radio buttons are concerned this is how I'm using it on my end:

 

  • Created a mutually exclusive radio button group named "Radio Button" and set the export values as "Template A", "Template B", Template C".
  • Created my template pages using the Organize  Pages tool and set these templates as hidden ("Template A, Template B, and Template C)
  • Created three text fields named them "myTextFieldA", "myTextFieldB", "myTextFieldC" respectively
  • Created a button to reset the Radio Button group (default state for my radio buttons is unchecked)

 

Use this script on first Radio Button (with export value "Template A"):

 

 

 

 

this.getField("myTextFieldA").display = display.visible;
this.getField("myTextFieldB").display = display.hidden;
this.getField("myTextFieldC").display = display.hidden;

this.resetForm(["myTextFieldB","myTextFieldC"]);

/// Obtain the template name "myTemplate":
var A = this.getTemplate("Template A");

// Prevent file size inflation; overlay the template on the last page of the document:
var XO = A.spawn(-1, true, false);

 

 

 

 

Use  this script on second Radio Button (with export value "Template B"):

 

 

 

 

this.getField("myTextFieldA").display = display.hidden;
this.getField("myTextFieldB").display = display.visible;
this.getField("myTextFieldC").display = display.hidden;

this.resetForm(["myTextFieldA","myTextFieldC"]);


//Delete the last page from the document. The (0-based) page number of the last page in the document is this.numPages - 1
this.deletePages({ nStart: this.numPages - 1 });

/// Obtain the template name "myTemplate":
var B = this.getTemplate("Template B");

// Prevent file size inflation; overlay the new template on the last page :
var XO = B.spawn(-1, true, false);

 

 

 

 

 

Then place this script on third Radio Button (with export value "Template C"):

 

 

 

 

this.getField("myTextFieldA").display = display.hidden;
this.getField("myTextFieldB").display = display.hidden;
this.getField("myTextFieldC").display = display.visible;

this.resetForm(["myTextFieldA","myTextFieldB"]);

//Delete the last page from the document. The (0-based) page number of the last page in the document is this.numPages - 1
this.deletePages({ nStart: this.numPages - 1 });

/// Obtain the template name "myTemplate":
var C = this.getTemplate("Template C");

// Prevent file size inflation; overlay the template on last page:
var XO = C.spawn(-1, true, false);

 

 

 

 

As you can see, selecting radio button with export value "Template A" will spawn my hidden page labeled "Template A" and overlay it on the last page of my PDF.

 

Clicking on the subsequent radio button will delete that last page and replace it by overlaying the corresponding template based on the script.

 

Last clicking on the reset button resets all radio button to its default state which is unchecked.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 02, 2020 0
Community Beginner ,
Oct 04, 2020

Copy link to clipboard

Copied

Thank you so much! This is extremely helpful!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 04, 2020 1