java - 如何在 itext 7 中使用 opentype 功能?
问题描述
我使用 fontlab studio,我使用 OpenType 在其中创建连字,是否可以在 itext 7中使用连字?
解决方案
可以在使用 iText7 编写的文本(包括连字)上应用 OpenType 功能,但它需要pdfCalligraph - iText7 插件。
另请参阅此答案iText 变音符号(例如 D̂、M̂ 等)在 PDF 上未正确显示,特别是下一段:
有关pdfCalligraph的更多信息,请参阅“iText 7:构建块”教程的第 2 章(请滚动至本章末尾)以了解其工作原理。您可以在此处获得 pdfCalligraph 的免费试用版。
当您拥有 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();
推荐阅读
- python - str.replace 除非字符串后跟某些文本
- python - 将列表元素分成单独的数字并写入记事本文件
- python - Python:我可以使 read_excel sheet_name 不区分大小写吗
- node.js - 节点 cron 在特定日期后每 7 天运行一次
- android - 如何在 onclick 中使用私有 void?
- python - 如何打印字典的名字?
- python - NumPy 矩阵运算在不同的机器上产生不同的结果
- firebase - 挣扎于 Flutter 中的 authStateChanges
- php - 在php中将数组键转换为字符串
- php - cake php 版本迁移