iTextSharp - Is it possible to set a different font color for the same cell and row? iTextSharp - Is it possible to set a different font color for the same cell and row? asp.net asp.net

iTextSharp - Is it possible to set a different font color for the same cell and row?


What you want to do is create 2 Chunk objects, and then combine these into 1 Phrase which you will add to the cell.

var blackListTextFont = FontFactory.GetFont("Arial", 28, Color.BLACK);var redListTextFont = FontFactory.GetFont("Arial", 28, Color.RED);var titleChunk = new Chunk("Title", blackListTextFont);var descriptionChunk = new Chunk("Description", redListTextFont);var phrase = new Phrase(titleChunk);phrase.Add(descriptionChunk);table.AddCell(new PdfPCell(phrase));

Have a look at http://www.mikesdotnetting.com/Article/82/iTextSharp-Adding-Text-with-Chunks-Phrases-and-Paragraphs


Try like this to set a different foreground color in a pdf cell:

var FontColour = new BaseColor(35, 31, 32);var Calibri8 = FontFactory.GetFont("Calibri", 8, FontColour);PdfPCell R3C2 = new PdfPCell(new Paragraph("Hello", Calibri8));R3C2.BorderWidth = 0f;R3C2.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;table.AddCell(R3C2);


For VB.net Use the following function

 Public Function CreateFont(size As Integer, Optional style As Integer = iTextSharp.text.Font.BOLD) As iTextSharp.text.Font        Dim FontColour = New BaseColor(193, 36, 67)  'Color code        Return New iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, size, style, FontColour) End Function Dim p As New Paragraph p.Add(New Paragraph("Your Sentence Here", CreateFont(12, iTextSharp.text.Font.BOLDITALIC))) pdfDoc.Add(p)