Nikshep
Nikshep

Reputation: 2115

iTextSharp ListItem different font's issue

I need to display a text like this on my PDF using iTextSharp

" Recommendation to enhance your ability to learn and remember

Concentrate: In order to remember something you need to learn it. Learning is possible only if you pay enough attention to it. You will retain information for a longer period of time only if you concentrate properly at the time of learning.

Involve as many senses as possible: The physical act of rewriting information can help imprint it onto your brain. Even if you’re a visual learner, read out loud what you want to remember. If you can recite it rhythmically, even better. "

I tried to do this by

ListItem firstRecommend = new ListItem(new Chunk("Concentrate:", new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD, BaseColor.BLUE)));
            firstRecommend.Add(new Chunk("In order to remember something you need to learn it. Learning is possible only if you pay enough attention to it. You will retain information for a longer period of time only if you concentrate properly at the time of learning."
                                , new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLUE)));
            recommendationList.Add(firstRecommend);

But it did not work the whole text is bold instead of part bold.

This also does not work

ListItem firstRecommend = new ListItem(new Chunk("Concentrate:", new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD, BaseColor.BLUE))); firstRecommend.Chunks.Add(new Chunk("In order to remember something you need to learn it. Learning is possible only if you pay enough attention to it. You will retain information for a longer period of time only if you concentrate properly at the time of learning." , new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLUE))); recommendationList.Add(firstRecommend);

Only the bold part is shown on the pdf , as I noticed that ListItem.Chunks is readonly.

How to get this working ??

Upvotes: 0

Views: 2759

Answers (1)

agarcian
agarcian

Reputation: 3965

You could try creating a paragraph first, then adding it to the listitem.

See the following code.

    Chunk c1 = new Chunk("Concentrate:", new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD, BaseColor.BLUE)));
    Chunk c2 = new Chunk("In order to remember something you need to learn it. Learning is possible only if you pay enough attention to it. You will retain information for a longer period of time only if you concentrate properly at the time of learning.", new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLUE)));

    Pharagraph p2 = new Pharagraph();
    p2.Add(c1);
    p2.Add(c2);

    ListItem firstRecommend = new ListItem(p2);

Upvotes: 4

Related Questions