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

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

问题描述

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

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(为了记住一些东西,您需要学习它.只有当您对它有足够的关注时,才有可能进行学习.只有在您正确地专注于该信息的情况下,您才能保留较长时间的信息.学习的时间." ,新的Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN,11,Font.NORMAL,BaseColor.BLUE))); RecommendationList.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.

如何使它工作?

推荐答案

您可以先尝试创建一个段落,然后将其添加到列表项中.

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天全站免登陆