Copy link to clipboard
Copied
I am doing a massive overhaul of our forms for my job, and I have written several scripts to lock all fields when a button is pressed or to automatically insert today's date in a field so the user cannot backdate the form, but I am wondering if I could write a script that turns the borders of my form fields off when the document is printed. I need to keep the borders so that users who open the forms in Adobe Reader can see the fields, but I don't love the look of that when the document is printed. I would also love for the borders to turn back on after printing.
I only have basic Java/JavaScript knowledge, and most of the scripts I've "written" have been adapted from various responses I've seen posted here. I'd love some feedback on this particular issue!
Copy link to clipboard
Copied
Use the "Will Print" and "Did Print" scripts under "Document Actions". You can find this tool by searching the tools for "Document Actions"
If you want to turn off borders for all fields. Use this code.
// Will Print Script
var oFld;
for(var i=0;i<this.numFields;i++){
oFld = this.getField(this.getNthFieldName(i));
oFld.tmp = oFld.strokeColor;
oFld.strokeColor = ["T"];
}
// Did Print Script, restores borders.
for(var i=0;i<this.numFields;i++){
oFld = this.getField(this.getNthFieldName(i));
oFld.strokeColor = oFld.tmp;
}
Note that the border style will also need to be remove and restored.
Copy link to clipboard
Copied
Enter the following script as a WillPrint script:
for(var i = 0; i < this.numFields; i++)
{
var fieldName = this.getNthFieldName(i);
var oFld=this.getField(fieldName);
if(oFld==null){continue}
oFld.strokeColor=color.transparent;
}
Enter the following as a DidPrint script (assuming the borders were black to start with):
for(var i = 0; i < this.numFields; i++)
{
var fieldName = this.getNthFieldName(i);
var oFld=this.getField(fieldName);
if(oFld==null){continue}
oFld.strokeColor=color.black;
}
Copy link to clipboard
Copied
You want to change border on all fields?
You can do it using document actions,'Document Will Print' and 'Document Did Print':
Will print:
for (var i=0; i<this.numFields; i++) {
var fieldName = this.getNthFieldName(i);
var field = this.getField(fieldName);
field.strokeColor = color.transparent;}
For 'Did print' change color to whichever you wish.
If you have radio buttons you may want to also change borderStyle.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more