I want my template pages to spawn in a certain order, in a certain place. Any help would be great. :)

I have a multiple page doc (for this example lets call it 5) where templates are spawned from the 3rd and 4th pages. Page 3 and 4 each have a unique checkboxes that will spawn different template pages. I want all the pages to spawn after page 4. I want them to spawn in numerical order. (Template1, Template2, Template3 etc...) or (Template2, Template3, Template5.... if user does not need Template1 or 4).

I am using this code

var v = event.target.value;
var t = this.templates;
var p = this.pageNum + 2;

for (var i = 0; i < t.length; i++){
if (t[i].name == "Template1") { // Checkbox2/page3 is "Template2"
if (v != "Off") {
t[i].spawn(p, false, false);
}
else {
this.deletePages(p, p);
}
}
}

on the checkboxes on page 3 and I am using this code

var v = event.target.value;
var t = this.templates;
var p = this.pageNum + 1;

for (var i = 0; i < t.length; i++){
if (t[i].name == "Template3") { //Checkbox2page4 is "Template4" if (v != "Off") {
t[i].spawn(p, false, false);
}
else {
this.deletePages(p, p);
}
}
}

on the checkboxes on page 4.

The two checkboxes on page3 have the same code, but different names (and different connected templates), ditto for page4.

Page1
Page2
Page3 (templates spawn 2 pages after this page)
page4 (templates spawn 1 pages after this page)
Page5

If I spawn more than one template from page 3, the first template is correct in the order, but the second template from page 3, will be put in front of the first template.

Page1
Page2
Page3
Page4
Template2 (spawned from page3 second)
Template1 (spawned from page3 first)
Page5

I would like to tell the templates to spawn in a certain order or just to spawn directly after templates already spawned. User will spawn them in the order they should be in.

Sorry for such a long question, I just wanted to be detailed as possible. I know this might be difficult thing to answer (or a lot of JavaScript) so thank you for any input on this or the way I am setting things up.


Peter Ottenbacher


Voted Best Answer

You will have to keep track of which templates are already there and where they are in your document, and then spawn the new template in the correct location. As you may know, you can specify where you want your spawned page to be inserted by using the nPage parameter. The trick now is to keep track of where you've added a template page. You can either determine this dynamically, every time you want to add a template. If you want to go that route, you need to know how the template field names are generated. When you spawn a new page from Template1, and you have a field name "Dummy" (an e.g. hidden field that you know exists on each template), and your template was spawned as the fifth page in the document, you will find that field as P4.Template1.Dummy - P4 because the pages start with page 0). You can then test if a certain field exists on a certain page and determine if the page was added via spawning a template, or if it's a "normal" document page.

You can also keep track of all your spawned pages by storing the information e.g. in a hidden listbox control.

Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com


By Karl Heinz Kremer   


Please specify a reason: