9
Acrobat Templates
The Role of Templates in PDF Form Architecture
The Role of Templates in PDF Form Architecture
Introduction
Acrobat JavaScript defines a
template
object that supports interactive form
architectures. In this context, a
template
is a named page within a PDF document that
provides a convenient format within which to automatically generate and manipulate a
large number of form fields. These pages contain visibility settings, and can be used to
spawn new pages containing identical sets of form controls to those defined within the
template.
As you learned earlier, it is possible to use templates to dynamically generate new content
within a document. Templates can be used to assure that your content is reusable, and can
be used for replicating the logic you previously created.
A template is used to reproduce the logic on a given page at any new location in the
document. This logic may include form fields such as text fields and buttons, digital
signatures, and embedded logic such as JavaScripts that email form data to another user.
To create a template based on a page, invoke the
doc
object’s
createTemplate
method, in which you will name your template and specify the page from which it will be
created. The code below creates a template called
myTemplate
based on page 5 of the
current document:
this.createTemplate({cName: "myTemplate", nPage: 5});
There are two steps required to generate pages based on a template contained in the
document:
1.
Select a template from the
doc
object’s
templates
property, which is an array of
template
objects.
2.
Spawn a page invoking the
template
object’s
spawn
method.
The following code adds a new page at the end of the current document that is based on
the first template contained in the document:
var myTemplateArray = this.templates;
var myTemplate = myTemplateArray[0];
myTemplate.spawn(this.numPages, false, false);
156
Acrobat JavaScript Scripting Guide