简体   繁体   中英

How to change color of a text field in pdfclown?

I want to fill in a PDF form. I am using library Pdfclown for this.

I have a problem changing the color of a TextField . I can change font size without problems, but not the color of the text.

I put the code where I managed to set values in the PDF form:

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);
        }
    }

}

DefaultStyle applies itself to TextField instances like this:

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

( apply(TextField) in DefaultStyle.java )

Thus, you might have to set

style.setGraphicsVisibile(true);

before applying your style to field .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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