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

前端 未结 3 778
春和景丽
春和景丽 2021-01-14 16:20

I am having hard time trying to generate PDF files containing Greek letters using itextpdf. I am reading the strings from an external source as UTF-8 strings. English letter

相关标签:
3条回答
  • 2021-01-14 16:56

    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 讨论(0)
  • 2021-01-14 16:58

    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.

    0 讨论(0)
  • 2021-01-14 17:08

    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...

    0 讨论(0)
提交回复
热议问题