Search code examples
javapdfitextacrofields

Can I use the BaseColor class in old iText versions?


I am trying to set BorderColor to an AcroField of my PDF. We are using an iText version that is at least 5 years old. I dont see any class named BaseColor in that version, whereas I've seen the following code being used in more recent versions of the iText library:

AcroFields form = New AcroFields (); form.setFieldProperty("text_2", "bordercolor", BaseColor.RED, null);

Is there are anyway I can successfully use BaseColor in the obsolete versions of iText?

I also have a follow-up question: Can I find bordercolor of a field in PDF using iText?


Solution

  • Just use:

    //import java.awt.Color;
    fields.setFieldProperty("text_2", "bordercolor", Color.BLUE, null);
    fields.setFieldProperty("text_2", "bordercolor", Color.RED, null);
    fields.setFieldProperty("text_2", "bordercolor", Color.GREEN, null);
    

    If you need a custom color, define it like this:

    Color custom = new Color(228,102,0);
    fields.setFieldProperty("text_2", "bordercolor", custom, null);