Call Us At: 701.866.2098

Acro-JavaScript: Flatten Form Fields


Developer Software Required: Adobe Acrobat A.K.A Adobe Acrobat Pro
End User Software Required: Adobe Reader A.K.A. Adobe Acrobat Reader

JavaScript can be used to lock down form fields or flatten .pdf form fields so entered data cannot be changed by a typical user. This can be extremely handy when a document is available to end users submitting filled forms to various departments where the department end users should not be changing contents submitted via the .pdf form.

To do this effectively, I typically append the code to the custom submit button within the .pdf form. For more information about the custom submit button, check out Acro-Javascript: Custom Submit Button.

Here’s the code used:

flattenFields()

function flattenFields() {

if (app.viewerType=="Reader") {

for (var i=0 ; i

var f = this.getField(this.getNthFieldName(i));

if (f==null) continue;

f.readonly = true;

}
}
}

Here’s the code with the Custom Submit Button code:

flattenFields()

function flattenFields() {

if (app.viewerType=="Reader") {

for (var i=0 ; i

var f = this.getField(this.getNthFieldName(i));

if (f==null) continue;

f.readonly = true;

}
}
var cToAddr = "travis@offtherichterdesign.com"
var cCCAddr = "service@offtherichterdesign.com"
var cBody = "Off The Richter Design: Business Training Request\n" + "\nThe attached file is the filled-out form. Please open it to review the data."
var cSubLine = "Business Training Request"
this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine + "Off The Richter Design", cMsg: cBody}); 
}

Addtionally, one can also leave specific form fields editable if desired. Here’s how we can accomplish this:

this.getField("submit").hidden = true;

flattenFields()

function flattenFields() {
if (app.viewerType=="Reader") {

for (var i=0 ; i<this.numFields ; i++) {

var fname = this.getNthFieldName(i);
if (fname!="Your Form Field Here" && "Your Other Form Field Here"){
this.getField(fname).readonly = true;
}
}
}
var cToAddr = "travis@offtherichterdesign.com"
var cCCAddr = "service@offtherichterdesign.com"
var cBody = "Off The Richter Design: Business Training Request\n" + "\nThe attached file is the filled-out form. Please open it to review the data."
var cSubLine = "Business Training Request"
this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine + "Off The Richter Design", cMsg: cBody}); 
}

Leave a comment

Your email address will not be published. Required fields are marked *