2

In section there is this jasper-report-character-encoding-in-pdf question.

The problem can not be solved in jasper report since it seems to be an problem (using iText v. 5.5.4)

Example code:

public class FontTest {

    /** The resulting PDF file. */
    public static final String RESULT = "pdf/fontTest.pdf";
    /** the text to render. */
    public static final String TEST = "\u1005\u101B\u1004\u103A\u1038\u1021\u1004\u103A\u1038\u1019\u103B\u102C\u1038\u1011\u100A\u103A\u101E\u103D\u1004\u103A\u1038\u1001\u103C\u1004\u103A\u1038";

    public void createPdf(String filename) throws IOException, DocumentException {
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        BaseFont bf = BaseFont.createFont(
            "lib/mm3.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        Font font = new Font(bf, 20);
        ColumnText column = new ColumnText(writer.getDirectContent());
        column.setSimpleColumn(36, 730, 569, 36);
        column.addElement(new Paragraph(TEST, font));
        column.go();
        document.close();
    }

    public static void main(String[] args) throws IOException, DocumentException {
        new FontTest().createPdf(RESULT);
    }
}

The font can be downloaded at mm3.ttf

Will render incorrectly as:

PDF RESULT

it should render as (in browser using same ttf)

Correct rendering

Just out of curiosity what is happening? (seems like certain char, with dotted circles should move backwards but this is not happening).

Is this a problem with .tff or that iText does not support these kind of fonts?

Community
  • 1
  • 1
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • 3
    The behavior you see is caused by the fact that iText doesn't support ligatures. You need one of the next, unreleased versions of iText. We'll release beta versions next year but only to customers. – Bruno Lowagie Dec 16 '15 at 07:01
  • @BrunoLowagie, 1000 thanks for your reply, look forward to new releases – Petter Friberg Dec 16 '15 at 10:11
  • Is it possible to address *glyphs* directly with this version of iText? Then all you need to know are the internal OpenType 'rules' for this font, and you'd be able to do the charcater translations in your code. – Jongware Dec 16 '15 at 23:12
  • .. for example, the sequence `\u1004\u103A` ("င ်") translates into glyph indexes `109` `158`, and these are referenced in a Chaining Context lookup. A lookup (Lookup #54) changes glyph index `158` to glyph index `233` and leaves the other character unchanged. Glyph index `233` has no Unicode code point assigned to it so you indeed need to translate from and to glyph indexes, and be able to refer to these indexes when rendering the text string. – Jongware Dec 17 '15 at 10:32
  • @Jongware thanks for your comments, I will look into if and how glyph can be accessed directly in itext (already seen this open question http://stackoverflow.com/questions/33748186/accessing-opentype-glyph-variants-in-itext). – Petter Friberg Dec 17 '15 at 10:45
  • Petter, thanks for pointing that one out! At the time it was asked I noticed it as well – edited it for clarity, upvoted, and favourited it. But no results yet, so I'm going to draw some more attention to it. – Jongware Dec 17 '15 at 11:15

2 Answers2

1

Converting Bruno Lowagie (Original developer of ) comment into answer (community wiki)

The behavior you see is caused by the fact that iText doesn't support ligatures. (Current version on github.com 5.5.8)

You need one of the next, unreleased versions of iText. We'll release beta versions next year (2016) but only to customers

Thanks to some bounty offered by @Rad Lexus this other question about accessing directly openType glyph in iText has an answer Accessing OpenType glyph variants in iText

Community
  • 1
  • 1
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
0

Please try the below codes,

string ZawgyiOnePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ZawgyiOne.ttf");
            BaseFont ZawgyiOneBaseFont = BaseFont.CreateFont(ZawgyiOnePath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

 iTextSharp.text.Font ZawgyiOneFont = new iTextSharp.text.Font(ZawgyiOneBaseFont, 9);
Angel F Syrus
  • 1,984
  • 8
  • 23
  • 43