In my last article I described how to access two undocumented identity object properties. I repeat that undocumented scripts are not published by Adobe so their functionality can disappear with a software update. I have three additional undocumented tricks for you today.
A lot of my knowledge came from reading and participating in the online forums, especially acrobatusers.com. Whenever I came across an interesting script, idea, or technique, I tested it out and saved it for future reference. Some of today’s tricks came from the previously mentioned forum. I believe in giving credit where credit is due so I’ll link to the questions and answers if I can find them. I discovered the undocumented identity object properties in my last post by trial and error when I had a hunch they might be buried in the software.
Validate An Email Address
There a lot of questions in the forums about how to validate an email address in a form field. By “validate” I don’t mean check the email address to make sure it is a validate email address, but rather check to ensure the entry conforms to a valid email pattern, i.e., something@something-dot-something. Most of the answers are variations of extensive regular expressions. But I came across this simple, undocumented, function that takes a text string as the input:
eMailValidate("something@something.com");
If the text string has a valid email structure it returns true. If not, it returns false. I use the following custom validation script in an email address form field:
if(event.value && !eMailValidate(event.value))
{
app.alert("Please enter a valid email address.",1);
event.value="";
}
The script validates whether the field has a value, and also whether the value is NOT a valid email address pattern. If both conditions are true (the field contains a value and that value is not a valid email pattern), a popup warning message appears and the field is cleared. If the second part is false (the value is a valid email pattern), the value is accepted (the first condition is obviously met by the field containing a value). The first condition is required in order to prevent the popup from appearing if the field is cleared or the form is reset. Remember, this function is not documented so it can disappear on you, or those for whom you programmed the form, without notice.
Static Text Color in a Popup Dialog
The color of the static text in a popup dialog box is black. It can be changed to red to make it stand out, or to signify a warning. This red-colored static text in a dialog is not documented. Here’s a simple dialog script you can run in the console:
var dlg = {
initialize:function (dialog){},
description:
{
elements:
[
{
type: "static_text",
name: "This static text element is red.",
item_id:"stat",
bold:true,
font:"dialog"
},
{
type: "ok_cancel",
}
]
}
}
app.execDialog(dlg);
Here’s the result you should see:
To change the color of the static text, insert this undocumented method that takes the static text item id as the input parameter into the intitialize function of the dialog:
dialog.setForeColorRed("stat");
Complete dialog:
var dlg = {
initialize:function (dialog){dialog.setForeColorRed("stat");},
description:
{
elements:
[
{
type: "static_text",
name: "This static text element is red.",
item_id:"stat",
bold:true,
font:"dialog"
},
{
type: "ok_cancel",
}
]
}
}
app.execDialog(dlg);
Result:
Substituting other colors for “Red” in the script produced not a function errors. Attempting to change the text color of other element types using this method did not work.
Reactivate a Dynamic Stamp
Once you apply a PDF stamp to a document it becomes a static image on the page. It can be resized, repositioned, or deleted. If the stamp has dynamic fields, either automatic or user-entered, these fields generally can’t be altered. The user would have to delete the stamp and start again.
There’s an undocumented way to delete the field data from a static stamp and reactive it so that automatic fields are filled again, and the popup dialog reappears. This is not the method we use for our editable dynamic stamps because the previous field data does not display in the popup dialog fields, so all data has to be re-entered. This is not much different from deleting the stamp and reapplying it. Joel Geraci explains how to do it in a comment on acrobatusers.com. Here’s the script:
var stamp = this.selectedAnnots[0];
var props = stamp.getProps();
delete props.APCosObj;
stamp.setProps(props);
Select the stamp and run the script above in the console. The fields in the static stamp will be cleared. If the stamp has automatic date/time fields, they will be updated to the current date and time. If the stamp has a popup dialog, the dialog will be activated to fill in the stamp fields.
I don’t really see a use for this trick, except maybe creating a one-click toolbar button to activate the script above (this first line of code would be replaced by a search for the stamp to identify it, rather than selecting it) instead of using the stamps menu. The stamp would first need to placed on the document.