About us | News | Contact
iText ® Licenses Support   
You are here: Home > Forums > iText in Action — Second Edition > Part 3: Essential iText skills > Chapter 11: Choose the right font
User login
  • Request new password

Arabic Characters

Submitted by Anonymous Newbie on Mon, 03/21/2011 - 11:49

Hello,
I'm able to display English characters but I'm not able to display Arabic characters.
Can u please help me on this?

BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1256", false);
PdfContentByte cb = writer.getDirectContent();
cb.beginText();
cb.setFontAndSize(bf_helv, 12);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text + " Center", 250, y_line1, 0);
cb.endText();

‹ How can I check if a specific character is supported in a font Can I define a background color for a font? ›
  • Login to post comments

Use the correct font and writing direction

Submitted by Bruno Lowagie on Mon, 03/21/2011 - 12:01.

There are two major issues at play in your snippet:

  1. Read the Missing characters FAQ entry. Cp1256 is the encoding for Arabic, but Helvetica doesn't know this encoding, neither will many other fonts. Use a font with support for Arabic, and use the encoding BaseFont.Identity_H. If you use Cp1256, you tell iText to use a simple font, and you'll only be able to use 256 glyphs. For languages such as Arabic, you should use a composite font (and Unicode). Read section 11.2 to find out the difference.
  2. Arabic is written from right to left, so you can't use PdfContentByte.showTextAligned(). You need to use ColumnText if you want to add the text at an absolute position, and you need to set the run direction with the setRunDirection() method. This is explained in section 11.3.4 entitled "Writing text from right to left".
  • Login to post comments
Content © 2010 1T3XT BVBA