如何配置iText以支持亚洲字符? [英] How to configure iText to support Asian characters?
问题描述
我的Java应用程序使用iText创建PDF。有时内容是亚洲的,这是行不通的。亚洲字符不可见。
My Java application creates PDFs using iText. Sometimes the content is Asian, which does not work. The Asian characters are not visible.
我在iText下载页面上找到了 iTextAsian.jar
,但是没有知道如何使用它。
I found iTextAsian.jar
on the iText download page, but don't know how to use it.
目标是使用我最喜欢的字体作为默认字体。但是当一个字符不可用时,该字符将使用其他字体。我看过,iText可以自动选择字体,但是如何配置呢?
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?
我也希望所有必需的字体都包含在PDF中,所以用户不要必须在他们的计算机上安装亚洲字体。
I also want all required fonts to be included in the PDF, so users don't have to install Asian fonts on their computers.
推荐答案
- 你可以定义一个FontSelector和然后添加你的字体(fontSelector.AddFont)。现在iText将使用fontSelector.Process方法从下一个定义的字体中选择不可用的字符。
- 亚洲字符通常是Unicode,所以你必须设置BaseFont.IDENTITY_H而不是Ansi一些(如FontFactory.GetFont(tahoma,BaseFont.IDENTITY_H))。
- 如果是RTL,则需要将文本包装在具有run direction属性的元素中并将其设置为rtl。
这篇关于如何配置iText以支持亚洲字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!