在使用Jasperreports時(shí),經(jīng)常會(huì)遇到無法在PDF格式報(bào)表當(dāng)中顯示中文,這時(shí)需要我們修改報(bào)表中文字的下面三個(gè)屬性實(shí)現(xiàn):
1. Font : 宋體
2. Pdf Font Name : STSong-Light
3. Pdf Encoding :Identity-H (Unicode with horizontal writing)
還有一種情況,可能我們在本地測試的情況下報(bào)表顯示正常,一旦部署到BDF2當(dāng)中可能出現(xiàn)類似下面的字體找不到的異常:
字體找不到異常
net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'Arial' is not available to the JVM.
這種情況對于將應(yīng)用部署到Linux操作系統(tǒng)環(huán)境下的應(yīng)用特別常見,一旦您遇到這種問題,那么我們需要做的就是利用iReport將缺少的字體打包并放置我們應(yīng)用的classpath環(huán)境下即可。iReport字體打包操作如下:
首先打開IReport的工具/選項(xiàng)/Fonts,點(diǎn)擊Install Font:

點(diǎn)擊瀏覽按鈕,選擇字體庫的ttf文件。


點(diǎn)擊完成,實(shí)現(xiàn)字體庫的導(dǎo)入操作,這樣在IReport設(shè)計(jì)器中就可以使用這些字體了,如果需要在web工程使用該字體庫,則可以選擇已配置的字體庫(可以是多個(gè)),點(diǎn)擊右側(cè)的Export asextension按鈕,將這些字體庫導(dǎo)出成jar,放到classpath下使用,這樣web應(yīng)用就可以使用這些字體庫,解決了中文問題。

更多建議: