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

Delete specific pages when checkbox unchecked in PDF

New Here ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

I have two check boxes that I want to spawn templates when checked, and delete those pages when unchecked. I have no issue spawning the templates, but I am unable to determine the page number once they are spawned to be able to delete these once unchecked.

 

  • Checkbox1 spawns/should delete template1
  • Checkbox2 spawns/should delete template2 & template3

 

I understand the pages start at 0, but the output does not make sense when I print to console. The three templates are hidden.

 

I check checkbox1 then checkbox2, and uncheck in the same order and the console prints the following for the page numbers:

temp1pages=0
temp2pages=-1,-11
temp3pages=0

 

My code currently is this for checkbox1:

if(this.getField("Checkbox1").isBoxChecked(0) == true){
    var temp1 = this.getTemplate("template1");
    temp1.spawn();
}
else{
    var temp1pages = this.getField("template1_field").page+1;
    this.deletePages(temp1pages);
}

and for checkbox2:

if(this.getField("Checkbox2").isBoxChecked(0) == true){
    var temp2 = this.getTemplate("template2");
    var temp3 = this.getTemplate("template3");
    temp2.spawn();
    temp3.spawn();
}
else{ 
    var temp2pages = this.getField("template2_field").page+1; 
    this.deletePages(temp2pages);
    var temp3pages = this.getField("template3_field").page+1;
    this.deletePages(temp3pages);
}

 

 

 

 

TOPICS
Acrobat SDK and JavaScript , Windows

Views

203

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
community guidelines
Community Expert ,
May 25, 2021 May 25, 2021

Copy link to clipboard

Copied

What does you display in the console?

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
community guidelines
Community Expert ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

LATEST

Because you choose not to rename the fields they are duplicates of each other. That means the page property returns an array of numbers, not just one number. The page number of a field that's located on a hidden template page is -1, which is what you're seeing as the first value of temp2pages. The second value is the page number of the spawned version, which is what you should use in your code.

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