In jasper-reports 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 itext 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:
it should render as (in browser using same ttf
)
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?
\u1004\u103A
("င ်") translates into glyph indexes109
158
, and these are referenced in a Chaining Context lookup. A lookup (Lookup #54) changes glyph index158
to glyph index233
and leaves the other character unchanged. Glyph index233
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