I'm trying to generate PDF file that contains Hebrew words.

When file is created all the Hebrew letters are deleted and only the English one are

in the file.

Can any one help me with this problem?

I'm using iText 5.4.3

This is my code when i add a new paragraph

    Paragraph p0 = new Paragraph("טופס קריאת שירות");
    BaseFont unicode = BaseFont.createFont("assets/fonts/arial.ttf", BaseFont.IDENTITY_H , BaseFont.EMBEDDED);
    Font fontHebrew = new Font(unicode, 12, Font.NORMAL);
    p0.setAlignment(Paragraph.ALIGN_CENTER);
    p0.setFont(fontHebrew);

    //add paragraph to document    
    doc.add(p0);

Thank's.

有帮助吗?

解决方案

The code you added is wrong on many levels.

  1. You're adding Hebrew characters in source code. These characters can get lost if the file is saved using the wrong encoding, if the file is compiled using the wrong encoding, etc... Use the Unicode notation instead of actual characters.
  2. Maybe not wrong, but to be checked: you're using arial.ttf, shouldn't you be using arialuni.ttf? Also: make sure you pack the ttf in your APK (you wouldn't be the first to forget to ship a resource).
  3. I can't read Hebrew, but I know it's written from right to left. RTL isn't supported in the Paragraph class, only in PdfPCell and ColumnText.

See the examples to find out how it's done: say_peace.pdf is done using a table; ligatures_2.pdf is done using a column (the second example is in Arabic, but it's the same principle as Hebrew).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top