如何在itext 7中使用opentype功能?

时间:2018-09-29 22:29:11

标签: java pdf itext

我使用fontlab studio,使用OpenType在其中创建连字,是否可以在itext 7中使用连字

1 个答案:

答案 0 :(得分:1)

可以在使用iText7编写的文本(包括连字)上应用OpenType功能,但是需要 pdfCalligraph -一个iText7插件。

另请参见此答案iText diacritic characters such as D̂, M̂ and so on not displayed correctly on PDF,特别是下一段:

  

有关pdfCalligraph的更多信息,请参见chapter 2 of the "iText 7: building blocks"教程(请滚动至本章末尾)以了解其工作原理。您可以获得pdfCalligraph here的免费试用版。

使用pdfCalligraph时,必须显式启用连字,因为它们被视为可选功能。您可以使用下一个代码段作为示例:

PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
Document document = new Document(pdfDocument);
PdfFont font = PdfFontFactory.createFont(FONT_PATH, PdfEncodings.IDENTITY_H);
document.setProperty(Property.FONT, font);

String text1 = "Testing ligatures feature in layout (off): Fff akt ikto!";
Paragraph p = new Paragraph(text1);
document.add(p);

String text2 = "Testing ligatures feature in layout (on): Fff akt ikto!\nAnd also kerning: AWAWAWA";
Paragraph pLiga = new Paragraph(text2);
pLiga.setProperty(Property.TYPOGRAPHY_CONFIG, new TypographyConfigurator()
        .addFeatureConfig(
                new LatinScriptConfig()
                        .setLigaturesApplying(true)
                        .setKerningFeature(true)
        ));
document.add(pLiga);

document.close(); 

示例输出: Image showing effect of applying opentype features via pdfCalligraph