使用iText Java的pdf中的日文/中文文本 [英] Japanese/Chinese text in pdf using iText Java

查看:405
本文介绍了使用iText Java的pdf中的日文/中文文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在java中使用iText将xml web响应中的日文/中文文本添加到pdf中。我将KozMinPro-Regular.ttf复制到我的c:\ WINDOWS \ .Fonts文件夹后尝试了以下代码但是失败了。

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字体= new Font(BaseFont.createFont(KozMinPro-Regular,UniJIS-UCS2-H,BaseFont.EMBEDDED),10);

任何人都可以帮助我吗?

Can anyone help me?

推荐答案

你应该使用 iTextAsian (额外的JAR文件)。

You should use iTextAsian (extra JAR file).

<的一些描述a href =http://grepcode.com/file/repo1.maven.org/maven2/com.lowagie/itext/2.1.0/com/lowagie/text/pdf/fonts/cmap_info.txt\"rel =nofollow iTextAsian.jar 内的> cmap_info.txt

Some description of cmap_info.txt inside iTextAsian.jar.


请注意,无论如何使用
方法 BaseFont.createFont 传递
'embedded'参数的值,不会嵌入字体
。要了解
为什么,请阅读以下
信息。

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.

查看PDF文件时Acrobat
Reader中使用的字体
使用CJK字体将以
的形式下载一个或多个字体包。你可以自己从
这个URL
下载这些fontpack:
http://www.adobe.com/products/acrobat/acrrasianfontpack.html

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

在此页面上,你可以找到
以下信息:如果作者
的Adobe(R)便携式文档
格式(PDF)文件在PDF中嵌入CJK和
中欧(CE)字体
文档,然后任何语言版本的
Adob​​e Reader(R)软件将能够
在任何
系统上显示CJK和CE文本而无需其他软件。

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.

如果PDF文档的作者使用
CJK或CE字体但未在文档中嵌入
,那么正确的
需要以
顺序安装字体才能在
非本机系统上查看Adobe PDF文件。

如果需要,字体在PD中未被嵌入F文件,你不应该使用绝对路径的字体文件。

创建一个包含字体文件的jar文件,并将其包含在类路径条目中。

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.

这篇关于使用iText Java的pdf中的日文/中文文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆