2

I am using itext-7.0.1 on top of Linux Mint 17.1
I am trying to add Non-ASCII text (Hebrew) to a PdfDocument, but all the Hebrew letters are missing from the text:

private void writePdf(Entity entity, OutputStream outputStream) throws IOException {
  PdfWriter pdfWriter = new PdfWriter(outputStream);
  PdfDocument pdfDocument = new PdfDocument(pdfWriter);
  Document document = new Document(pdfDocument);
  PdfFont font = PdfFontFactory.createRegisteredFont("open sans", "UTF-8"); //A correctly registered font
  document.add(new Paragraph("Some English Letters").setFont(font)); //This will appear well inthe PDF
  document.add(new Paragraph(entity.getName()).setFont(font)); //This will appear as a blank line
  System.out.println(entity.getName()); //Written correctly to stdout
  document.add(new Paragraph(entity.getId()).setFont(font)); //This will appear correctly in the PDF
  document.close();
  System.exit(-1);
}

Summing the code above: All the ASCII text (English and digits) is written correctly to the PDF, but the Hebrew letters (entity.getName()) is written as a blank line. The above font is correctly typed in a word processor, however in order to verify this, I have tried other fonts that caused the same result.

There a lot of socumentation in itext-5. Should I switch to itext-5 instead of 7?

Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101
Guy Yafe
  • 991
  • 1
  • 8
  • 26
  • Your question is missing the specification of the PDF library you are using. – Adrian Colomitchi Oct 19 '16 at 08:18
  • 1
    Maybe I am missing your point, but I have mentioned this in the header: itext-7 – Guy Yafe Oct 19 '16 at 08:19
  • Stupid question probably but it has to be asked: are you sure the open sans font file you're using supports the hebrew glyphs? – Gimby Oct 19 '16 at 08:23
  • "UTF-8" is not a valid encoding for a font in a PDF. Please try "Identity-H" instead. – mkl Oct 19 '16 at 08:24
  • Some others needed to [register the font first](http://stackoverflow.com/a/24794304/620908). – Adrian Colomitchi Oct 19 '16 at 08:26
  • *There is a lot of documentation about iText 5. Should I switch to iText 5 instead of 7?* -> all of the existing documentation about iText 5 on http://developers.itextpdf.com is in the process of being ported to iText 7. There won't be significant additions to iText 5 documentation, but the iText 7 documentation will continue to grow beyond what was available for iText 5. – Amedee Van Gasse Oct 19 '16 at 08:31
  • 1
    The font was registered properly earlier in the flow. I have verified that the font supports Hebrew glyphs by installing it in a word processor. After setting the Identity-H attribute, the characters are shown. However, they are eritten LTR instead of RTL, but looks like this is a know issue and I am looking how to solve this. – Guy Yafe Oct 19 '16 at 08:34
  • 2
    You have already discovered that "UTF-8" is not the right encoding. Now you want LTR. That is only possible if you introduce the pdfCalligraph add-on, please read http://developers.itextpdf.com/content/itext-7-building-blocks/chapter-2-working-rootelement (near the end of the page). – Bruno Lowagie Oct 19 '16 at 18:05

0 Answers0