Japanese/Chinese text in pdf using iText Java

巧了我就是萌 提交于 2019-12-19 03:54:29

问题


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("KozMinPro-Regular", "UniJIS-UCS2-H", BaseFont.EMBEDDED), 10);

Can anyone help me?


回答1:


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.




回答2:


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);


来源:https://stackoverflow.com/questions/5785775/japanese-chinese-text-in-pdf-using-itext-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!