Nitin
Nitin

Reputation: 59

how can i change color of text in a cell in itext pdf?

I just want to change color of "PAN DETAILS"(cell text) in my code please tell with a good example.

 PdfPTable table2 = new PdfPTable(1);
         table2.setWidthPercentage(100);
         PdfPCell cellsss;
         cellsss = new PdfPCell(new Phrase("PAN DETAILS"));
         cellsss.setBorderColorTop(BaseColor.BLACK);
         cellsss.setColspan(0);
         cellsss.setBorderColor(BaseColor.RED);
         BaseColor myColorpan = WebColors.getRGBColor("#b60548");
         cellsss.setBackgroundColor(myColorpan);
         cellsss.setHorizontalAlignment(Element.ALIGN_CENTER);
         table2.addCell(cellsss);
         cellsss = new PdfPCell(new Phrase("PAN DETAILS"));
         cellsss.setBorderColor(BaseColor.BLACK);
         document.add(table2);

Upvotes: 2

Views: 16276

Answers (1)

MrT
MrT

Reputation: 594

This is maybe a duplicate. But anyway: The Font class holds the color so you have to set the color in the Font-class.

Font font = new Font(bf_times)
font.setColor(Color.BLACK);

This must be set in the Phrase:

new Phrase("PAN DETAILS", font)

From the duplicate.

Upvotes: 3

Related Questions