Limit # of spawned template

Hello all,

my pdf form has 3 templates.
How to make sure that each of the templates can be spawned only 1 time.

Thanks in advance!


Florian Bartmann


2 Answers

You would have to set up a document-level variable for every template, and test for its value whenever you attempt to spawn the Template. If the value of the variable is the initial value, you may spawn, and then immediately change the variable value.

If you allow for deleting the spawned pages, you could reset the value of that variable.

Example:

In a document-level script define and initialize the variable (important: outside of a function):

var t1spawned = false ;

Code snippet for spawning:

if (t1spawned) {
// Template has already been used
app.alert("can not spawn Template T1") ;
} else {
// Template has not yet been used
this.getTemplate("T1").spawn(…) ;
t1spawned = true ;
}

where you have to adjust the name of the Template, as well as the arguments of spawn()

Hope this can help.

Max Wyss.


Max Wyss   

Max is on the right track, but his approach fails if you save the file after spawning the template once, and then re-open it. The document level variable will be re-initialized to false, which means that you can spawn one more page from that template.

I would store the document state in a hidden form field: E.g. use a hidden checkbox that starts out as unchecked, and gets checked when you spawn the template the first time. You then check that checkbox instead of checking the document level variable. For our three templates, you would need three different hidden checkboxes, or a field type that can hold the state of all three templates in one control, but in that case, checking the data would get a bit more complex.

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


Karl Heinz Kremer   


Please specify a reason: