开发者

itext PDF - Greek letters are not appearing in the resulting PDF document

I am having hard time trying to generate PDF files c开发者_高级运维ontaining Greek letters using itextpdf. I am reading the strings from an external source as UTF-8 strings. English letters appear in results but not the Greek ones. Searching for the problem, I think it might be related to the font used. I do not know what ttf file to use if this is the problem. Here is how am creating the font

 BaseFont bfTimes = BaseFont.createFont(FontFactory.HELVETICA,"UTF-8", BaseFont.EMBEDDED);
 Font times = new Font(bfTimes, 12, Font.BOLD);

any help is heartily appreciated!


You need to use a font that has Greek characters in it. You may find Greek unicode fonts here.

You can check an example here on using unicode fonts from the author of itext.


Actually the problem could lead to the way you create the font. Instead of passing "UTF-8" as codepage try to use "CP1253".

BaseFont bfTimes = BaseFont.createFont(FontFactory.HELVETICA,"CP1253", BaseFont.EMBEDDED);
Font times = new Font(bfTimes, 12, Font.BOLD);

Btw, BaseFont has static string constnts for CP1250, CP1252 and CP1257...


I used this code:

BaseFont fonty = BaseFont.createFont("assets/ARIALBD.TTF", BaseFont.IDENTITY_H,       BaseFont.NOT_EMBEDDED);
     fonty.setSubset(true);
     Phrase myName = new Phrase("Your Not Latin Words", new Font(fonty,12));
     ColumnText.showTextAligned(canvas,
             Element.ALIGN_LEFT, myName, 66, 400, 0);

i had to paste the ARIALBD.TTF to assets folder

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜