I need to add japanese/chinese text from xml web response to pdf using iText in java. I tried the following code after copying the KozMinPro-Regular.ttf to my c:\WINDOWS\Fonts folder but failed.
Font font = new Font(BaseFont.createFont("Ko开发者_开发问答zMinPro-Regular", "UniJIS-UCS2-H", BaseFont.EMBEDDED), 10);
Can anyone help me?
You should use iTextAsian (extra JAR file).
Some description of cmap_info.txt inside iTextAsian.jar.
Note that whatever value you pass for the 'embedded' parameter with the method BaseFont.createFont, the font WILL NOT BE embedded. To understand why, please read the following information.
The fonts that are used in Acrobat Reader when viewing a PDF file that uses CJK fonts will be downloaded in one or more font packs. You can download these fontpacks yourself from this URL: http://www.adobe.com/products/acrobat/acrrasianfontpack.html
On this page, you can find the following information: "If the author of an Adobe (R) Portable Document Format (PDF) file embeds CJK and Central European (CE) fonts in a PDF document, then any language version of Adobe Reader (R) software will be able to display the CJK and CE text on any system without additional software.
If the author of the PDF document uses CJK or CE fonts but does not embed them in the document, then the correct fonts will need to be installed in order to view the Adobe PDF file on non-native systems."
If needed fonts is unembedded in PDF file, you should not use absolute path for font files.
Create a jar file with font files, and include it in classpath entry.
I havn't tested this, but according to this page
Usage of Installed fonts are something like this.
Font font = new Font(BaseFont.createFont("C:\\Windows\\Fonts\\KozMinPro-Regular.ttf,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 10);
精彩评论