6
Using Acrobat JavaScript in Forms
Using JavaScript to Secure Forms
These objects, in combination, provide you with the means to digitally sign or encrypt a
document. Once you have built a list of authorized recipients, you may then encrypt the
document using the
doc
object’s
encryptForRecipients
method, save the
document to commit the encryption, and email it to them.
For example, you can obtain a list of recipients for which the encrypted document is
available, and then encrypt the document:
// Invoke the recipients dialog to select which recipients
// will be authorized to view the encrypted document:
var oOptions = {
bAllowPermGroups: false,
cNote: "Recipients with email and certificates",
bRequireEmail: true,
bUserCert: true
};
var oGroups = security.chooseRecipientsDialog(oOptions);
// Build the mailing list
var numCerts = oGroups[0].userEntities.length;
var cMsg = "Encrypted for these recipients:\n";
var mailList = new Array;
for (var i=0; i<numCerts; i++) {
var ue = oGroups[0].userEntities[i];
var oCert = ue.defaultEncryptCert;
if (oCert == null) oCert = ue.certificates[0];
cMsg += oCert.subjectCN + ", " + ue.email + "\n";
var oRDN = oCert.subjectDN;
if (ue.email) mailList[i] = ue.email;
else if (oRDN.e) mailList[i] = oRDN.e;
}
// Now encrypt the document
this.encryptForRecipients(oGroups);
120
Acrobat JavaScript Scripting Guide