【问题标题】:iText chapter font overrides paragraph fontiText 章节字体覆盖段落字体
【发布时间】:2015-02-10 12:01:11
【问题描述】:

这是我用来构建 Chapter 的代码:

Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC)
Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL)
Chunk chunk = new Chunk(doc.title, this.chapterFont).setLocalDestination(title);
Chapter chapter = new Chapter(new Paragraph(chunk), i);
chapter.setNumberDepth(0);

paragraphs.each { paragraph ->
    chapter.add(new Paragraph(paragraph, paragraphFont))
}

this.document.add(chapter);

当我创建文档并将其写入文件时,段落以与章节标题相同的字体(16 Helvetica)显示。章节标题的字体设置是否会覆盖段落中的某些内容?

【问题讨论】:

    标签: java groovy itext


    【解决方案1】:

    我无法重现该问题,我做了一个名为 ChapterAndTitle 的示例,如下所示:

    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Chunk chunk = new Chunk("This is the title", chapterFont);
    Chapter chapter = new Chapter(new Paragraph(chunk), 1);
    chapter.setNumberDepth(0);
    chapter.add(new Paragraph("This is the paragraph", paragraphFont));
    document.add(chapter);
    

    结果如下:

    段落的字体看起来不错。与您的代码示例的唯一区别是我正在使用String 创建一个Paragraph 对象。目前尚不清楚您的 paragraphs 对象包含什么。也许字体是在您的 paragraph 对象级别定义的。

    【讨论】:

      猜你喜欢
      • 2013-06-12
      • 2012-02-27
      • 1970-01-01
      • 2012-04-06
      • 1970-01-01
      • 2016-05-14
      • 2016-10-24
      • 2011-08-14
      • 1970-01-01
      相关资源
      最近更新 更多