9
Acrobat Templates
Spawning Templates
Template Syntax and Usage
In this first example, all the templates will be spawned once, the field names will not be
unique in each resultant page (
bRename
will be
false
), and the resultant pages will be
appended to the end of the document (
bOverlay
will be
false
). The
oXObject
parameter will be used to prevent size inflation:
// Obtain the collection of templates:
var t = this.templates;
// Spawn each template once as a page appended at the end:
for (var i = 0; i < t.length; i++)
t[i].spawn(this.numPages, false, false);
In this next example, the same template will be spawned 10 times, will overlay onto pages 0
through 9 (
bOverlay
will be
true
), and the field names will be unique on each page
(
bRename
will be
true
):
// Obtain the template:
var t = this.templates;
var T = t[0];
// Prevent file size inflation by using the XObject. Do this by
// spawning once, saving the result (an XObject), and passing
// the resultant XObject to the oXObject parameter in
// the subsequent calls to the spawn method:
var XO = T.spawn(0, true, true);
for (var i = 1; i < 10; i++)
T.spawn(i, true, true, XO);
In this next example, we will retrieve the template named
myTemplate
, overlay it onto
pages 5 through 10 (
bOverlay
will be
true
), and use the same field names on each page
(
bRename
will be
false
):
// Obtain the template name "myTemplate":
var t = this.getTemplate("myTemplate");
// Prevent file size inflation:
var XO = t.spawn(5, true, false);
// Spawn the remaining pages:
for (var i = 6; i <= 10; i++)
t.spawn(i, true, false, XO);
158
Acrobat JavaScript Scripting Guide