iTextSharp - 是否可以为同一个单元格和行设置不同的字体颜色? [英] iTextSharp - Is it possible to set a different font color for the same cell and row?
本文介绍了iTextSharp - 是否可以为同一个单元格和行设置不同的字体颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用带有以下代码的iTextSharp.dll:
I am using the iTextSharp.dll with the following code:
var Title = "This is title";
var Description = "This is description";
Innertable.AddCell(new PdfPCell(new Phrase(string.Format("{0} {1}", Title, Description.Trim()), listTextFont)) { BackgroundColor = new BaseColor(233, 244, 249), BorderWidth = 0, PaddingTop = 4, PaddingLeft = -240, PaddingBottom = 5, HorizontalAlignment = Element.ALIGN_LEFT });
我们可以为标题和描述设置不同的字体颜色,但只使用单个单元格(即不创建新表)?
Can we set different font colors for title and description, but only using single cell (ie without creating a new table)?
非常感谢任何帮助。
推荐答案
你想要做的是创建2 Chunk
对象,然后将它们合并到1 Phrase
中你将添加到单元格。
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));
看看 http://www.mikesdotnetting.com/Article/82/iTextSharp-Adding-Text-with-Chunks-Phrases-and-Paragraphs
这篇关于iTextSharp - 是否可以为同一个单元格和行设置不同的字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文