Reputation: 37
I'm having a problem with iText when I'm trying to create a PDF that contains characters like the ones in the title. What happens is that the accent circonflexe does not sit properly above the letter but rather right next to it or (depending on what font I use) somewhat "merged" into it (see screenshot below where I used FreeSans).
I know that all the characters that have this problem are "composite" characters. What I mean by this is that they are composed of two unicode characters. For example the "D̂" is represented as "\u0044\u0302" whereas all the usual characters are of course represented as "\uXXXX". So I'm pretty sure that it has to do with this. For example an "Ê" which has a normal unicode representation is displayed just fine.
Here is a tiny code snippet that hopefully contains everything you need to know:
String TEXT = "\u0044\u0302 \u004A\u030C \u004C\u0302 \u004D\u0302 \u004E\u0302 \u0064\u0302 \u006C\u0302 \u006D\u0302 \u006E\u0302";//D̂ J̌ L̂ M̂ N̂ d̂ l̂ m̂ n̂
BaseFont bf = BaseFont.createFont("FreeSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
document.add(new Paragraph(TEXT, font));
Any help would be highly appreciated.
Thanks in advance!
Upvotes: 1
Views: 1136
Reputation: 1916
You'll need to use iText 7 with the module pdfCalligraph. This kind of composing requires access to the OTF tables to align correctly the chars depending on size, height, etc.
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.
Upvotes: 3