Previous
((diff / 60) / 60) / 24 + " days since 4/11/1976");
console.println("It has been " +
(((diff / 60) / 60) / 24) / 365 + " years since 4/11/1976");
The output of this script would look something like:
It has been 718329600 seconds since 4/11/1976
It has been 11972160 minutes since 4/11/1976
It has been 199536 hours since 4/11/1976
It has been 8314 days since 4/11/1976
It has been 22.7780821917808 years since 4/11/1976
The following example shows the addition of dates.
/* Example of date arithmetic. */
/* Create a date object containing the current date. */
var d1 = new Date();
/* num contains the numeric representation of the current date. */
var num = d1.valueOf();
/* Add thirteen days to today’s date. */
/* 1000 ms / sec; 60 sec / min; 60 min / hour; 24 hours / day; 13 days */
num += 1000 * 60 * 60 * 24 * 13;
/* Create our new date that is 13 days ahead of the current date. */
var d2 = new Date(num);
/* Print out the current date and our new date using util.printd */
console.println("It is currently: " + util.printd("mm/dd/yyyy", d1));
console.println("In 13 days, it will be: " + util.printd("mm/dd/yyyy", d2));
The output of this script would look something like:
It is currently: 01/15/1999
In 13 days, it will be: 01/28/1999
Acrobat Forms and Security
Security in Acrobat takes on the form of restricting access to a document, restricting
permissions for a form once it has been opened, and digital signatures.
Restricting Access
If the author desires to restrict access to the form in its entirety then the standard security
model in Acrobat can be selected and an open password defined that requires a user to type in a
password before opening the form. Other security handlers exist and are provided by third
party developers as plug-ins and may also be useful. E.g. using a public/private key
Acrobat Forms - JavaScript Object Specification 61
infrastructure to lock a form for a particular set of people or allowing a form to expire after a
certain time period.
The ability to set a user password is accessed using the Save As function by choosing the
appropriate security handler and configuring its settings.
Restricting Permissions
The standard security model in Acrobat is accessible at document save time and allows you to
set the following restrictions on the document: printing, changing the document, selecting text
and graphics, and adding and changing annotations and form fields.
Once a form has been authored it is often useful to lock the form so that it may be filled in but
cannot be tampered with using the forms tool. For example, after authoring a form may be
posted on a Web site. In order to preserve the form integrity it needs to be shielded from any
changes to its formulae or internal data routines.
If the changing the document restriction is selected, the user can fill-in form fields and add
annotations but cannot author or modify form fields or change the background text using the
TouchUp plug-in.
In addition, once a form has been filled in, it is often desirable to lock the entire document so
that it cannot be changed whatsoever. In filling out a tax or other sensitive form, the user may
wish to save the document so that no further changes to the document are allowed. In order to
disallow both fill-in and authoring, the changing the document and the adding and changing
annotations and form fields restrictions must be selected.
Digital Signatures
Although these form fields do not restrict access or permissions, they do allow an author or
user to verify that a document has not been changed after a signature has been applied.
An author may digitally sign a form thus signifying that it has been released for fill-in. A user
can verify the signature to make sure that the form has not been tampered with and is thus
Acrobat Forms - JavaScript Object Specification 62
“official”. A blind signature (signed without any appearance) is often useful in this situation
and can be created via the pull right menu in the signatures pane.
After fill-in a user can also sign the document either by using the signing tool or filling in a
pre-authored signature field, thus ensuring that the form undergoes no further changes without
detection.
Working with Signature Fields 4.0
Signature fields allow the user to digitally sign a document. Once a signature is applied to the
document any subsequent changes to the document will cause the signature to indicate that the
“Document has been changed after signing”.
A signature field’s value is read-only. An unsigned signature has a null value. Once the field
has been signed its value is non-null.
When crafting a custom script for when the signature field is signed remember to allow for
resetting the form (i.e. the field’s value is set to null). For example, imagine a form where
upon signing a signature field that all fields whose names starts with “A” are locked and all
fields whose names start with “B” are locked. We might start with a script fragment, to be
executed at signature time, looking something like this:
/* This example is incorrect. */
var f = this.getField("A");
/* Lock all A fields. */
f.readOnly = true;
f = this.getField("B");
/* Unlock all B fields. */
f.readOnly = false;
This is a typical operation for many forms. This script is incorrect and when the form is reset
it will lock and unlock the wrong fields. Instead, it should check the value of the signing event
and react accordingly:
var bLock = (event.value != "");
var f = this.getField("A");
/* Lock A on sign, unlock on reset. */
f.readOnly = bLock;
f = this.getField("B");
/* Unlock B on sign, lock on reset. */
f.readOnly = !bLock;
There is a convenience routine available for your use called AFSignatureLock() in AForm.js
(see JavaScript Locations and Loading) that performs the programmatic equivalent of the simple
locking user interface in the signature properties dialog. This allows you to easily lock and
unlock all fields, a particular list of fields, or all fields but those specified. The example is re-
coded using this convenience routine below:
var bLock = (event.value != "");
AFSignatureLock(this, "THESE", "A", bLock);
Acrobat Forms - JavaScript Object Specification 63
AFSignatureLock(this, "THESE", "B", !bLock);
See the comments in AForm.js for more details.
Acrobat Forms - JavaScript Object Specification 64
Previous