I am displaying some content in a List to show it in a pdf file.
Every thing is working fine , but Now I want some text in a List Item Should be Bold.
For Example :
This is ListItem Bold Text.
How can I do this ?
Here is my code :
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);
EDIT
I’ve tried this :
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)));
But this didn’t worked
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Please take a look at the answer of this question: How can I use regular and bold in a single String?
The answer talks about a Paragraph, but it also works for a ListItem as ListItem is a subclass of Paragraph:
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));
You can add as many Chunk objects using as many different fonts as you want.
Method 2
You can do this by using Paragraph and Chunks like below:
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);
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0