Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure iText to support Asian characters?

My Java application creates PDFs using iText. Sometimes the content is Asian, which does not work. The Asian characters are not visible.

I found iTextAsian.jar on the iText download page, but don't know how to use it.

The goal is to use my favorite font as default. But when a character is not available an other font is used for this character. I have read, iText can select fonts that way automaticaly, but how to configure this?

I also want all required fonts to be included in the PDF, so users don't have to install Asian fonts on their computers.

like image 253
Witek Avatar asked Nov 22 '11 14:11

Witek


1 Answers

  • You can define a "FontSelector" and then add your fonts (fontSelector.AddFont). Now iText will choose the not available char from the next defined font by using the fontSelector.Process method.
  • Asian characters are usually Unicode so you have to set "BaseFont.IDENTITY_H" instead of Ansi ones (such as FontFactory.GetFont("tahoma", BaseFont.IDENTITY_H)).
  • If it's RTL, you need to wrap your text in elements which have run direction property and set it to rtl.
like image 136
VahidN Avatar answered Nov 09 '22 00:11

VahidN