1. 程式人生 > >iReport解決匯出PDF解決不支援中文

iReport解決匯出PDF解決不支援中文

從網上把jasperreports-6.0.0-project.zip下載下來,解壓

建立一個Maven工程

把剛才解壓zip中/demo/fonts裡面的複製東西過來,一個ttf代表字型.把主要的東西複製過來,不必要的字型刪除可以.

修改fonts.xml如下

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>

	<fontFamily name="宋體">
        <normal>net/sf/jasperreports/fonts/dejavu/simsun.ttf</normal>
        <bold>net/sf/jasperreports/fonts/dejavu/simsun_bold.ttf</bold>
        <italic>net/sf/jasperreports/fonts/dejavu/simsun.ttf</italic>
        <boldItalic>net/sf/jasperreports/fonts/dejavu/simsun.ttf</boldItalic>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
        <exportFonts>
            <export key="net.sf.jasperreports.html">'宋體', Arial, Helvetica, sans-serif</export>
            <export key="net.sf.jasperreports.xhtml">'宋體', Arial, Helvetica, sans-serif</export>
        </exportFonts>
    </fontFamily>
    
    
    
    	<fontFamily name="微軟雅黑">
        <normal>net/sf/jasperreports/fonts/dejavu/msyh.ttf</normal>
        <bold>net/sf/jasperreports/fonts/dejavu/msyhbd.ttf</bold>
        <italic>net/sf/jasperreports/fonts/dejavu/msyh.ttf</italic>
        <boldItalic>net/sf/jasperreports/fonts/dejavu/msyh.ttf</boldItalic>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
        <exportFonts>
            <export key="net.sf.jasperreports.html">'微軟雅黑', Arial, Helvetica, sans-serif</export>
            <export key="net.sf.jasperreports.xhtml">'微軟雅黑', Arial, Helvetica, sans-serif</export>
        </exportFonts>
    </fontFamily>

</fontFamilies>

修改jasperreports_extension.properties如下

net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.dejavu=net/sf/jasperreports/fonts/fonts.xml

然後打包到倉庫

在專案中依賴下這個jar包過來,然後就支援中文了.

		<dependency>
			<groupId>net.sf.jasperreports</groupId>
			<artifactId>jasperreports-fonts</artifactId>
			<version>6.0.0</version>
		</dependency>

效果就跟上面DEMO一樣

以上就是解決ireport匯出pdf不支援中文過程