3

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

}

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104

1 Answers1

1

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.

mkl
  • 90,588
  • 15
  • 125
  • 265
  • Thanks 'mkl'. Applying your solution has changed textfield frame's foreground not the text. But anyway, for my application it is good enough for the time being. – Xabier Fernandez Jan 03 '16 at 18:10
  • Ah, I see. Once you asked for the text color, more often, though, for the text field color. I mainly thought of the latter... – mkl Jan 03 '16 at 19:38
  • I looked at the code once more. As far as I can see, black / default is hardcoded as text color. – mkl Jan 05 '16 at 07:36
  • @XabierFernandez Thus... Did my answer solve your question? Or are there any issues left – mkl Jan 06 '16 at 11:18
  • Hi mkl, thanks for your answer. Pity I can't give you a positive vote, I am a newbie. – Xabier Fernandez Jan 06 '16 at 12:07
  • As it is your question, you should be able to accept an answer... there should be a tick on the left of the answer, if you click it, you mark the answer as accepted answer. – mkl Jan 06 '16 at 12:23