3

我想填写一份 PDF 表格。我正在为此使用库 Pdfclown。

我在更改 a 的颜色时遇到问题TextField。我可以毫无问题地更改字体大小,但不能更改文本的颜色。

我将代码放在我设法在 PDF 表单中设置值的位置:

public void setPDF(String Valor, String aField) {
    Form form = document.getForm();

    for (Field field : form.getFields().values()) {
        if (aField.equals(field.getName())) {
            DefaultStyle style = new DefaultStyle();
            style.setForeColor(DeviceRGBColor.get(Color.red));
            String newValue = Valor;                 
            field.setValue(newValue);                        
            style.apply(field);
        }
    }

}

4

1 回答 1

1

DefaultStyle适用于这样的TextField实例:

...
if(isGraphicsVisibile())
{
    composer.beginLocalState();
    composer.setLineWidth(lineWidth);
    composer.setFillColor(getBackColor());
    composer.setStrokeColor(getForeColor());
    composer.drawRectangle(frame, 5);
    composer.fillStroke();
    composer.end();
}
...

apply(TextField)DefaultStyle.java中)

因此,您可能必须设置

style.setGraphicsVisibile(true);

在申请style之前field

于 2016-01-02T23:28:35.777 回答