在输入文本时,如何更改PDF表单字段背景



我正在创建一个PDF表单以分发给人们。当文本没有输入到表单上的任何字段时,我希望它保持透明,但当有人在其中输入文本时,我想要字段的背景颜色变为白色。

我发现这个页面描述了如何使用JavaScript,所以我将它添加到PDF中的JavaScripts文档中,但它不起作用。默认情况下,字段仍然具有相同的透明背景。

使用或不使用JavaScript,我如何实现我想要的目标?我正在使用Acrobat Pro DC。谢谢

将此脚本放入字段的自定义格式脚本中

/* Turns off default field highlighting. Normally you'd put this in a doc level script it's just here for completeness */
app.runtimeHighlight = false;
/* The rest of this belongs in the custom format script */
var field = event.target;
if (field.value == field.defaultValue) {
/* set the fillColor is the field value is the same as the default (generally an empty string) */
field.fillColor = color.ltGray
}
else {
field.fillColor = color.transparent
}

我在这里有一个运行的示例文件。

最新更新