Reputation: 109
How to set bold and italic to a word in itext pdf.
for example:
"Hello World"
in one sentence
please advice me.
Upvotes: 6
Views: 14851
Reputation: 855
stumbled across this question while looking for the same thing. I think the existing answers are out of date for more recent versions of iText (Im using 5.0.6). Here's how I was able to do it:
Phrase phrase = new Phrase();
phrase.add(new Chunk("Hello ", FontFactory.getFont(FontFactory.TIMES_BOLD)));
phrase.add(new Chunk("World", FontFactory.getFont(FontFactory.TIMES_ITALIC)));
document.add(phrase);
Hopefully this helps someone ;)
Upvotes: 4
Reputation: 160
One sentence:
var x = new Phrase()
{
new Chunk("Hello ", new iTextSharp.text.Font(iTextSharp.text.Font.TIMES_ROMAN, 11, iTextSharp.text.Font.BOLD)),
new Chunk("World", new iTextSharp.text.Font(iTextSharp.text.Font.TIMES_ROMAN, 11, iTextSharp.text.Font.ITALIC))
});
Upvotes: 2
Reputation: 677
Please check this one:
Font font1 = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
Chunk hello = new Chunk("Hello", font1);
Chunk world = new Chunk("World",
new Font(Font.TIMES_ROMAN, 10, Font.ITALIC));
document.add(hello);
document.add(world);
Upvotes: 7