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

Checkbox JavaScript that toggles spawning of template, or deletion of page.

New Here ,
Aug 07, 2018 Aug 07, 2018

Copy link to clipboard

Copied

I'm using the following code as an action to spawn a hidden page template using a checkbox. The JavaScript works, but the issue is that each time I click the check box (check/uncheck) it will spawn a new page. I would like to toggle the checkbox to spawn the template (check) or delete the page (uncheck). 

Please note, this will be installed on machines that use Acrobat Reader, though the spawn functionality seems to work just fine.

I am using the following code as an action within each checkbox:

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

a.spawn(1,false,false);

Thanks for the help! I am very new to coding and acrobat!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.1K

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
community guidelines
Community Expert ,
Aug 07, 2018 Aug 07, 2018

Copy link to clipboard

Copied

You didn't say, but I'm assuming this is a MouseUp action? If not then it needs to be.

The solution is to qualify the code with the state of the checkbox.

if(event.target.value == "Off")

   this.deletePage(2);

else

{

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

    a.spawn(1,false,false);

}

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

Votes

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
community guidelines
New Here ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

Hi Thom,

Thanks for the help. Yes I am running the JavaScript on a mouseUp action.

I tried your code, and unfortunately , it does not work.

It will spawn the new page upon click.

Upon uncheck, it does nothing.

Votes

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
community guidelines
Community Expert ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

Look at the console for errors.

deletePage is wrong you must use deletePages.

Votes

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
community guidelines
New Here ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

While this works for 2/4 "sub forms" it does not work for all of them. How can I be sure to correlate pages to spawn/delete when check/unchecked out of "order" that I have set for them.

Votes

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
community guidelines
Community Expert ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

What code do you use?

Votes

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
community guidelines
New Here ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

I am using the following JavaScript to perform each action upon MouseUp. There a four check boxes the user has to spawn a subform:

if(event.target.value == "Off")

   this.deletePages(1);

else

{

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

    a.spawn(1,false,false);

}

Additionally I have a last page as a signature page that I do not want spawned but to remain at the end. How do I do that?

Votes

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
community guidelines
Community Expert ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

You spawn for all 4 check boxes the same template page?

Votes

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
community guidelines
New Here ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

I have four templates that I need to spawn after the first page and before the last page. Each template has their own check box.

Checkbox1 (Spawns Template1)

if(event.target.value == "Off")

   this.deletePages(1);

else

{

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

    a.spawn(1,false,false);

}

Checkbox2 (Spawns Template2):

if(event.target.value == "Off")

   this.deletePages(2);

else

{

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

    a.spawn(2,false,false);

}

Checkbox3 (Spawns Template3):

if(event.target.value == "Off")

   this.deletePages(3);

else

{

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

    a.spawn(3,false,false);

}

Checkbox4 (Spawns Template4& Template5 with two MouseUp javascript Actions)

if(event.target.value == "Off")

   this.deletePages(4);

else

{

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

    a.spawn(4,false,false);

}

Does that help?

Votes

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
community guidelines
Community Expert ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

You can spawn all templates after the first page.

Votes

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
community guidelines
New Here ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

My issue is that not all pages are deleting properly. Especially when they a spawned out of order (e.g. Template2 and Template4) as the page numbers are not the same as what the code is prompting to delete.

Votes

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
community guidelines
Community Expert ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

You didn't mention that you had multiple pages. This is more complicated and the solution is more complicated.

First, you need to be able to do some simple debug.  Had you looked at the console window you would have realized immediately that there was a syntax error in the "deletePage()"  function name, and then you could have looked it up in the Acrobat JS  Reference.

Here's the JS reference: Acrobat DC SDK Documentation

Next you need to be able to use the Console Window. There's a video tutorial here:Free Video Content & Full Listing of Available Videos

Now, for a solution you need a way to uniquely identify each of the templates. The easiest method is to place a field on each page that has a unique name. If there are uniquely named fields already on the form, the use them. Then this code will work for removing the page in question:

if(event.target.value == "Off")

{

    oFld = this.getField("Template1Fld");

   this.deletePages(oFld.page[1]);

}

else

{

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

    a.spawn(1,false,false);

}

Notice that the field page property is an array. After spawning there are two copies of this field, one on the original template, and one on the spawned page. The page number for the template is -1, and it is the first entry. Obviously we don't want that

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

Votes

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
community guidelines
Community Expert ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

Want you spawn template3 after template1 and template2 and before template4?

Votes

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
community guidelines
Advocate ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

I had various applications where pages could be spawned after any page, before or after already spawned pages.

In such a situation, in order to keep the field names unique and consistent, it is necessary to save all field values from subsequent pages, delete all subsequent spawned pages, respawn in correct order, and restore the field values. It may be a little bit messy, but those forms all worked, and some are still in active use.

Votes

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
community guidelines
New Here ,
Jun 11, 2019 Jun 11, 2019

Copy link to clipboard

Copied

LATEST

Help! I think I tried everything. It simply does not work. Fading in and out with the script works. Has Yemen found a working solution? This is not compatible with Acrobat Reader.Urgent! Thank you

Votes

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
community guidelines