20130307

BIRT在Tomcat环境下生成PDF报表缺少文字的解决

Author:  WinkCategories:  LinuxNo Comments »

最近在使用发布Mifos项目时,利用Mifos系统报表功能(BIRT)生成的PDF报表文档中,总是缺少很多汉字,无论这些文字是写在报表项目源文件中的,还是从MySQL取出的,都是如此。一番分析之后,终于解决了该问题,于是备注下来,以备后用。

首先分析一下BIRT项目包中的“fontsConfig.xml”文件(位于项目下形如“org.eclipse.birt.report.engine.fonts_xxxxx”目录内),发现有以下大段代码:

<font-paths>
	<path path="C:/windows/fonts" />
	<path path="d:/windows/fonts" />
	<path path="e:/windows/fonts" />
	<path path="f:/windows/fonts" />
	<path path="g:/windows/fonts" />
	<path path="C:/WINNT/fonts" />
	<path path="d:/WINNT/fonts" />
	<path path="e:/WINNT/fonts" />
	<path path="f:/WINNT/fonts" />
	<path path="g:/WINNT/fonts" />
	<path path="/usr/X/lib/X11/fonts/TrueType" />
	<path path="/usr/share/fonts/default/TrueType" />
	<path path="/usr/openwin/lib/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/euro_fonts/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/iso_8859_2/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/iso_8859_5/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/iso_8859_7/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/iso_8859_8/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/iso_8859_9/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/iso_8859_13/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/iso_8859_15/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/ar/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/hi_IN.UTF-8/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/ja/X11/fonts/TT" />
	<path path="/usr/openwin/lib/locale/ko/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/ko.UTF-8/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/KOI8-R/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/ru.ansi-1251/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/th_TH/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/zh_TW/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/zh_TW.BIG5/X11/fonts/TT" />
	<path path="/usr/openwin/lib/locale/zh_HK.BIG5HK/X11/fonts/TT" />
	<path path="/usr/openwin/lib/locale/zh_CN.GB18030/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/zh/X11/fonts/TrueType" />
	<path path="/usr/openwin/lib/locale/zh.GBK/X11/fonts/TrueType" />
	<path path="/usr/X11R6/lib/X11/fonts/TrueType" />
	<path path="/usr/X11R6/lib/X11/fonts/truetype" />
	<path path="/usr/X11R6/lib/X11/fonts/tt" />
	<path path="/usr/X11R6/lib/X11/fonts/TTF" />
	<path path="/usr/X11R6/lib/X11/fonts/OTF" />
	<path path="/usr/share/fonts/ja/TrueType" />
	<path path="/usr/share/fonts/truetype" />
	<path path="/usr/share/fonts/ko/TrueType" />
	<path path="/usr/share/fonts/zh_CN/TrueType" />
	<path path="/usr/share/fonts/zh_TW/TrueType" />
	<path path="/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType" />
</font-paths>

其实这是BIRT定义如何找寻系统字体目录,包括Windows和各种Linux系统。其次,在同目录下“fontsConfig_linux.xml”文件中,有如下代码:

<composite-font name="all-fonts" default="Lucida Sans Typewriter">
	<font font-family="Lucida Sans Typewriter" catalog="Western" />
	<font font-family="ZYSong18030" catalog="Chinese" />
	<font font-family="Baekmuk Batang" catalog="Korean" />
	<font font-family="Kochi Mincho" catalog="Japanese" />
</composite-font>

这意味着对于中文,BIRT系统主要使用的是ZYSong18030(中易宋体)来表达。该Mifos发布使用是Ubuntu,在上面的各个系统字体目录中,的确也无法找到这个字体,所以问题就出在这里。

于是首先下载ZYSong18030字体备用链接),上传到服务器中后解压并挪到“/usr/share/fonts/zh_CN/TrueType”目录下。如果没有“zh_CN/TrueType”这两级目录,需要依次建立并改属主为“root”。然后使用“mkfontscale”命令生成“fonts.scale”文件(如果没有该命令则需要安装“font-util”包)。

最后重启Tomcat服务器即可,不过注意需要清空Tomcat的缓存文件。

You can follow any responses to this entry through the RSS 2.0 feed. Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Back to Page Top