Delete specific pages when checkbox unchecked in PDF
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);
}
