gpt4 book ai didi

java - 如何使用 itext 7 中的 opentype 功能?

转载 作者:行者123 更新时间:2023-12-02 10:45:59 27 4
gpt4 key购买 nike

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

最佳答案

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

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

For more info on pdfCalligraph, see the chapter 2 of the "iText 7: building blocks" tutorial (please scroll towards the end of the chapter) to find out how it works. You can get a free trial version of 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

关于java - 如何使用 itext 7 中的 opentype 功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52573064/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com