Copy link to clipboard
Copied
Hi ! i am working with acrobat DC (15) on Windows.
thanks to : Spawn a page using drop down box (JavaScript) , i am able to spawn a template.
I have a dropdown list with 3 choices (A,B and C) and a button submit ( the code from the topic are inside this button) and then i spwan a template.
However, i would like to delete the template if the user change his choice from A to B ...
i konw how to delete a page : {this.deletePages(1)} but where i could apply it ???
Thxxxxxxx !!!
Copy link to clipboard
Copied
In the same place where you're spawning the pages. You will need to first check if there's a need to delete such a page, though.
For example, you can check the total number of pages in the file (numPages property). If it's not the original number, delete the additional pages and then spawn the new ones.
Copy link to clipboard
Copied
I am really a newbie ... may i have some code ?? 😃
I have this :
// get the value from the dropdown control
var sel = this.getField("liste_qualif").value;
// determine the template name
var templateName = "";
switch (sel) {
case 1: templateName = "CRI";
break;
case 2: templateName = "FI";
break;
case 3: templateName = "FTI de FTI";
break;
case 4: templateName = "FTI";
break;
case 5: templateName = "IRI";
break;
case 6: templateName = "MCCI";
break;
case 7: templateName = "SFI";
break;
case 8: templateName = "STI";
break;
case 9: templateName = "TRI";
break;
}
// if we have a template name, spawn the template
if (templateName != "") {
var t = this.getTemplate(templateName);
t.spawn();
}
Copy link to clipboard
Copied
How many pages are there in the file before you spawn the template?
Are you always spawning the new pages as the last pages of the file?
Copy link to clipboard
Copied
i have 9 pages and yes it will always spawn at the last page
Copy link to clipboard
Copied
HI,
Will you always only spawn one page at the end of the document?
Regards
Malcolm
Copy link to clipboard
Copied
Yes, only one page 😃
Copy link to clipboard
Copied
Then you can use this code to delete all the spawned pages:
if (this.numPages>9) this.deletePages(9, this.numPages-1);
Copy link to clipboard
Copied
Sorry i misread, i have only one page ... but 8 templates which gonna spawn. I understood what you've wrote 😃 thx !!!
Copy link to clipboard
Copied
In that case replace "9" with "1" in the code above...
Copy link to clipboard
Copied
(assuming those templates are hidden, of course)
Copy link to clipboard
Copied
yes it is 😃