Set in bold and italics per word in itext pdf

How to set bold and italic word in itext pdf.

eg:

" Hello World"

in one sentence

please advise me.

+4
source share
3 answers

Please check it:

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);
+5
source

One suggestion:

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))
            });
+2
source

stumbled upon this question, looking for the same thing. I think the existing answers are deprecated for later versions of iText (Im using 5.0.6). Here is how I was able to do this:

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);

Hope this helps someone;)

0
source

Source: https://habr.com/ru/post/1532944/


All Articles