【问题标题】:iTextSharp ListItem different font's issueiTextSharp ListItem 不同字体的问题
【发布时间】:2012-02-10 11:42:41
【问题描述】:

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

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

专注:为了记住一些你需要学习的东西。只有当你足够关注它时,学习才是可能的。只有在学习时适当集中注意力,才能将信息保留更长时间。

涉及尽可能多的感官:重写信息的物理行为有助于将信息印在您的大脑上。即使您是视觉学习者,也要大声读出您想记住的内容。如果能有节奏地背诵,那就更好了。 "

我试着这样做

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

但它不起作用,整个文本都是粗体而不是部分粗体。

这也行不通

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("为了记住一些你需要学习的东西。只有你足够注意它才能学习。只有在你正确地集中注意力时,你才能将信息保留更长的时间。学习时间。” , 新字体(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLUE))); 推荐列表.Add(firstRecommend);

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

如何让它工作??

【问题讨论】:

    标签: c# itextsharp


    【解决方案1】:

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

    见以下代码。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-22
      • 1970-01-01
      • 1970-01-01
      • 2011-05-15
      • 1970-01-01
      • 2011-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多