Search code examples
javaitext

'com.itextpdf.text.html.WebColors' is deprecated


I am using iText library and having a code snippet given below:

BaseColor sectionFontColor = WebColors.getRGBColor("#ffffff");

Getting a warning message:

'com.itextpdf.text.html.WebColors' is deprecated

How to resolve this?


Solution

  • You are using iText version above 5.5.2. WebColors is deprecated from 5.5.2 onwards as per docs.

    BaseColor class supports default colors: WHITE, LIGHT_GRAY, GRAY, DARK_GRAY, BLACK, RED, PINK, ORANGE, YELLOW, GREEN, MAGENTA, CYAN & BLUE

    If you want to generate a different color apart from default colors, then you have to pass RGB values in the constructor of BaseColor.

    Example:

    // #ffffff hex code is for white color
    BaseColor sectionFontColor = BaseColor.WHITE;
    
    // if you want to have a different color, for example, Purple (#674ea7)
    BaseColor sectionFontColor = new BaseColor(103, 78, 167);
    

    Note: First parameter being the red value, second parameter being the green value & third parameter being the blue value in the BaseColor constructor.

    I have used this website color-hex.com to generate the hex code and RGB values for a particular color.