在PDF列表中大胆一些文本



我在列表中显示一些内容以在PDF文件中显示。

每件事都可以正常工作,但是现在我希望列表项中的一些文本应该大胆。

例如:

这是 ListItem Bold 文本。

我该怎么做?

这是我的代码:

 List lst_note = new List(List.ORDERED);
 lst_note.IndentationLeft = 10f;
 lst_note.Add(new iTextSharp.text.ListItem("This single **word** should be Bold", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10)));
 disclaimer.Add(lst_note);

编辑

我已经尝试过:

    Font bold  = new Font(FontFactory.GetFont(FontFactory.TIMES_BOLD, 10, Font.BOLD));
   lst_terms.Add(new iTextSharp.text.ListItem("Some Text "+ new Chunk("this should bold", bold), FontFactory.GetFont(FontFactory.TIMES_ROMAN, 10)));

但这没有起作用

请查看此问题的答案:如何在单个字符串中使用常规和粗体?

答案谈论了Paragraph,但它也适用于ListItem,因为ListItemParagraph的子类:

Font regular = new Font(FontFamily.HELVETICA, 12);
Font bold = Font font = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
ListItem li = new ListItem("NAME: ", bold);
li.Add(new Chunk("regular", regular));

您可以使用所需的多个不同字体添加尽可能多的Chunk对象。

您可以使用 ParagraphChunks进行此操作:

Chunk c1 = new Chunk("This single", new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL, BaseColor.BLACK)));
            Chunk c2 = new Chunk("word", new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, BaseColor.BLACK)));
            Chunk c3 = new Chunk("should be Bold", new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL, BaseColor.BLACK)));
            Paragraph p2 = new Paragraph();
            p2.Add(c1);
            p2.Add(c2);
            p2.Add(c3);
 List lst_note = new List(List.ORDERED);
 lst_note.IndentationLeft = 10f;
 lst_note.Add(new iTextSharp.text.ListItem(p2);
 disclaimer.Add(lst_note);

最新更新