加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – iTextSharp – 是否可以为同一个单元格和行设置不同的字体

发布时间:2020-12-15 17:42:47 所属栏目:百科 来源:网络整理
导读:我使用iTextSharp.dll与以下代码: 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 BaseCo
我使用iTextSharp.dll与以下代码:
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 });

我们可以为标题和描述设置不同的字体颜色,但只能使用单个单元格(即不创建新表格)?

在这件事上的任何帮助将不胜感激.

解决方法

您要做的是创建2个Chunk对象,然后将它们组合成1个短语,您将添加到单元格.
var blackListTextFont = FontFactory.GetFont("Arial",28,Color.BLACK);
var redListTextFont = FontFactory.GetFont("Arial",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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读