Livia Mitrică
Livia Mitrică

Reputation: 43

itext DeviceGrey not compatible to setBackgroundColor in Java project

I am using iText 7 and I am trying to set the background color of my pdf table.

Cell cell = new Cell(1, 3)
                .add((IBlockElement) new Paragraph("This is a header"))
                .setFont(f)
                .setFontSize(13)
                .setFontColor(DeviceGray.WHITE)
                .setBackgroundColor(DeviceGray.BLACK)
                .setTextAlignment(TextAlignment.CENTER);

But DeviceGray.WHITE and DeviceGray.BLACK give errors saying that they are not compatible. The message says that setBackgroundColor(com.itextpdf.kernel.colors.color) cannot be applied to com.itextpdf.kernel.color.DeviceGray

I also have the following imports

import com.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.kernel.color.DeviceGray;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.IBlockElement;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.UnitValue;

Upvotes: 0

Views: 129

Answers (1)

Livia Mitrică
Livia Mitrică

Reputation: 43

I realized the cause of my problem was mixing versions of io, kernel and layout. Set all of them to 7.1.10 and it works.

Upvotes: 1

Related Questions