如何设置基本字体颜色?

How to set basefont color?

我想更改我的基本字体颜色。

我使用了一个矩形来设置背景颜色,但是我不知道如何让我的字体变成白色,因为我正在使用 PdfContentByte 对象。

我尝试使用 Chunk 设置字体颜色,但 SetFontAndSize 覆盖了它。

BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);

iTextSharp.text.Font titreProgFont = FontFactory.GetFont("Times", 12, BaseColor.WHITE);

string nomProgramme, codeProgramme;
nomProgramme = "PROGRAMMEUR ANALYSTE";
codeProgramme = "LEA.1A";

Chunk titreProgChunk = new Chunk(nomProgramme + " (" + codeProgramme + ")", titreProgFont);

PdfContentByte cb2 = writer.DirectContent;
cb2.SaveState();
cb2.SetColorFill(BaseColor.GRAY);
cb2.Rectangle(200, 200, 200, 200);
cb2.Fill();
cb2.RestoreState();
cb2.BeginText();
cb2.SetFontAndSize(bfTimes, 12);
cb2.ShowTextAligned(PdfContentByte.ALIGN_CENTER, titreProgChunk.ToString(), 200, 200, 0);
cb2.EndText();

使用其中一种填充颜色更改字体颜色如cb2.SetColorFill(BaseColor.WHITE);