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

标签 java pdf itext

我使用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/

相关文章:

java - 我需要帮助修复 java 代码所需的输出需要 Fraction@55f96302\n 是一个错误

PDF 优化 Acrobat 与 Ghostscript

c# - ITextSharp 添加页码到合并的 pdf 中

itext - 将 itextsharp 条形码图像添加到 PdfPCell

java - 空游标返回

java - 将 AbstractDecolatedTextEditor 添加到 Eclipse 中的多页编辑器后的 NPE

java - 如何为 Java 指定服务器首选的 SSL 密码套件顺序?

PHPExcel 保存 PDF

pdf - 如何将 PDF 转换为低分辨率(但质量良好)的 JPEG?

java - 如何旋转页面而不是 iText 中的文本?