Elie Roux
Elie Roux

Reputation: 455

iText7: how can I specify OpenType features to be used by a PdfFont?

For complex scripts (Tibt in my case) I need to be able to specify some OpenType features that a PdfFont should use (see here for the ones to use with Tibt). I can't find any way to specify that to iText, and with the default features, the result is not OK.

Example:

public static void main(String args[]) throws IOException {
    final String notoPath = "/usr/share/fonts/truetype/noto/NotoSansTibetan-Regular.ttf";
    final PdfWriter writer = new PdfWriter("tibttest.pdf");
    final PdfDocument pdfDoc = new PdfDocument(writer);
    final Document doc = new Document(pdfDoc);
    PdfFont f = PdfFontFactory.createFont(notoPath, PdfEncodings.IDENTITY_H, true);
    doc.add(new Paragraph("༄༅། །སྒྲུབ།").setFont(f));
    doc.close();
}

produces a PDF that looks like:

Nok result

while it should look like:

Expected result

Is there a way to specify a list of OpenType features to use?

Upvotes: 0

Views: 343

Answers (1)

Amedee Van Gasse
Amedee Van Gasse

Reputation: 7634

Are you using the add-on pdfCalligraph? https://itextpdf.com/itext7/pdfcalligraph

If yes, then you are an iText customer with a support contract, and I recommend that you contact iText Software directly.

If no: you need pdfCalligraph to use OpenType features of complex writing systems like Tibt. See extended examples on the linked website. Because I don't see you loading a license key in your code, I assume that this is the case.

In case your particular language isn't yet supported by pdfCalligraph, we'll make sure to add it ASAP. But from the top of my mind I think that most Indic languages are supported. You can request a 30 day free trial license at https://pages.itextpdf.com/itext-7-free-trial-landing-page-1.html

Full disclosure: I am QA Engineer at iText Software.

Upvotes: 1

Related Questions