iTextSharp ListItem不同字体的问题 [英] iTextSharp ListItem different font's issue

查看:95
本文介绍了iTextSharp ListItem不同字体的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的PDF上使用iTextSharp显示这样的文字

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


建议以提高你的学习和记忆能力

专注:为了记住你需要学习的东西。只有你足够重视它才能学习。只有在学习时正确集中注意力,您才会保留更长时间的信息。

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. "

我试图通过

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.

这也不起作用

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(为了记住你需要学习它的东西。只有你足够重视它才能学习。只有当你有时,你才能保留更长时间的信息在学习时正确集中。
,new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN,11,Font.NORMAL,BaseColor.BLUE)));
recommendedList.Add(firstRecommend);

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

只有粗体部分显示在pdf上,因为我注意到ListItem.Chunks是只读的。

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

如何使这个工作?

推荐答案

你可以先尝试创建一个段落,然后将其添加到listitem。

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

请参阅以下代码。

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

这篇关于iTextSharp ListItem不同字体的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆