简体   繁体   English

基于Acrobat中表单字段值的动态字体颜色分配

[英]Dynamic font color assignment based on a form field value in Acrobat

I have a loan form that calculates a debt:income ratio. 我有一个贷款表格,可以计算债务:收入比率。 I want the field the ration is in (calculated field, no user input allowed) to change the font color based on the ratio. 我希望配给比例的字段(计算字段,不允许用户输入)根据比例更改字体颜色。

If the ratio is above 60%, then I want the font color to be an off-red (see color values below), another color if >= 35%, and normal if below 35%. 如果比率高于60%,那么我希望字体颜色为偏红色(请参见下面的颜色值),如果> = 35%,则为另一种颜色,如果低于35%,则为正常。

This is the code I've come up with... 这是我想出的代码...

if (event.value >= .6) {
    this.textColor = (255, 153, 0);
}
else if (event.value >= .35) {
    this.textColor = (204, 51, 0);
}
else {
    this.textColor = (0, 102, 153);
}

The code is in a custom validation. 该代码在自定义验证中。

This doesn't work. 这行不通。 What am I doing wrong? 我究竟做错了什么?

There were several problems with your code but also, you were running it in the wrong event. 您的代码有一些问题,但是您在错误的事件中运行它。 During a validation event, the value isn't actually committed yet. 在验证事件期间,该值尚未实际提交。 Use a custom Format script to change the appearance of a field after the value has been committed. 提交值后,请使用自定义格式脚本更改字段的外观。 See image. 见图片。 在此处输入图片说明

Then in your code, you need to get the value of the field triggering the script (event.target) and then you need to set the color property of it (event.target.textColor). 然后在代码中,您需要获取触发脚本的字段的值(event.target),然后需要设置其color属性(event.target.textColor)。 Also, colors in PDF are defined by using an array where the first element is the color space, then followed by values that range from 0 to 1. See revised code below. 此外,PDF中的颜色是通过使用数组定义的,其中第一个元素是颜色空间,然后是0到1的值。请参见下面的修订代码。

if (event.target.value >= .6) {
    event.target.textColor = ["RGB", 255/255, 153/255, 0];
}
else if (event.target.value >= .35) {
    event.target.textColor = ["RGB", 204/255, 51/255, 0];
}
else {
    event.target.textColor = ["RGB", 0, 102/255, 153/255];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM