How to configure iText to support Asian characters?
Asked Answered
A

1

7

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.

Additional answered 22/11, 2011 at 14:44 Comment(3)
They are not "symbols," they are characters.Manzanares
Do your users all have the Asian font pack installed with their PDF viewers or do you have control over the installed base of PDF viewers such that you can ensure that they do? If not, would using PDF embedded fonts make the resulting PDF too large -- iText embeds only the glyphs needed by the document?Azine
No control over users. It is a web application which creates PDFs. Very large PDFs are better then PDFs without asian characters. Next step would be to detect if user content contains asian characters and skip including extra fonts based on that.Additional
A
2
  • 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.
Astrodynamics answered 24/11, 2011 at 10:45 Comment(4)
Which fonts do I have to add via addFont()?Additional
BaseFont.IDENTITY_H embeds the selected .ttf fonts in the final PDF. So look for the fonts which have the complete characters of that language.Astrodynamics
Since users on websites can come from everywhere, I have to add fonts for all characters to the selector, right? How to find out, which (10?) free fonts together cover 99% of all characters?Additional
Yes, you need to add those fonts and only fontSelector.Process method is able to choose the correct one automatically. here are some free Asian and Arabic fonts : 1001freefonts.com/asian-fonts.php & freearabicfonts.com/Free_Arabic_FontsAstrodynamics

© 2022 - 2024 — McMap. All rights reserved.