Is it possible to set ARGB background color to IText PDF cell?

Carmine :

In iText PDF we can set background color to a cell like this

PdfPCell cell = buildCell(phrase, displayType, col);
cell.setBackgroundColor(new java.awt.Color(33, 150, 243, 153));

But it turns out that iText ignores the java.awt.Color opacity.

Is there any way to do this?

mkl :

Support for transparent cell background colors has been added in iText 5.5.7, more exactly in git commit 09ccaa728830a404e92fc3040dd3626198576fef.

You appear to use an older iText version, though, as indicated by your use of a java.awt.Color instead of a com.itextpdf.text.BaseColor.

Depending on the exact version of iText you may try and use a PdfPCellEvent implementation instead of setting the background color with setBackgroundColor. In that implementation you'd have to first save the graphics state, then set a PdfGState with transparency, fill the cell rectangle with the color, and restore the graphics state again.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=133716&siteId=1