ireport 4.1.1 导出PDF 引入外部中文字体
2011-10-10 15:28
477 查看
版本:iReport4.1.1
iReport默认情况下是不支持中文的,即便是自带的STSong-Light,虽能在预览视图里良好的显示正常、粗体、斜体、下划线等,但部署到应用后部分功能无效果,只能以正常字体显示。
如需完整使用以上的功能,需要装中文字体包导入到iReprot软件里去。
步骤如下:
安装字体:在菜单工具(tools)---->选项--->iReport---->fonts--->installfonts--->browse--->选择中文字体文件(simfang.ttf)
中文字体文件可以在系统文件夹 C:\WINDOWS\Fonts 找到你需要的字体。这里以 仿宋_GB2312 为例,如图选择相应的值。
--->下一步--->下一步--->下一步--->完成
这时在Fonts窗口中可以看到刚安装的字体了。
导出字体:选中刚安装的字体----Export as extension将刚导入的字体打包成*.jar文件导出。
根据个人习惯,我把它放在 C:\Program Files\Jaspersoft\iReport-4.1.1\ireport\fonts 文件夹下。
引用字体:切换到Classpath选项卡下,add jar---->找到刚导出的字体包将其导入,并勾上Reloadable。
这样我们就在iReprot里面可以用这个字体了。
使用字体时应注意
以调色板中的staticText为例:向页面上拖放一个staticText组件选中此组件,在属性窗口中找到如下几个属性
1,Font name 选择安装字体时所显示的名称,这里我选择的是仿宋_GB2312
2.PdfFontName, PdfEncoding, PdfEmbedded这三个属性全部清除。只需设置Font name一个即可。具体如下:
点击打开链接
If you have packed your TTFs in a font extension JAR, there is no reason for using the pdfFontName attributes in your JRXML.
Please remove them and make sure text fields have fontName, or have the fontName be inherited from a report default style.
Note that the three attributes pdfFontName, pdfEncoding, and isPdfEmbedded are now deprecated (replaced by settings inside font extensions).
I have tested your report and font extension JAR with iReport and it worked. Are you sure your font extension JAR is in the classpath at the time the PDF export is performed?
Is the PDF export occurring inside the same application that does the report filling?
注意。每一个要显示中文字体的组件都需要这样设定。这样就大功告成。
在应用程序中,同样需将导出的字体jar包放入classpath文件夹下。
实际上,按照以上的步骤完成后,在应用中仍然会报错FontFormatException。此问题困扰我很久很久。
最后发现在ireport 4.1.1版本中,使用Export as extension导出的字体jar包根本无法使用。里面的simfang.ttf文件大小竟然为0字节。不知道到底是谁的错误导致的。
无奈之下,手动将原始大小的simfang.ttf替换掉它。这才万事大吉。
iReport默认情况下是不支持中文的,即便是自带的STSong-Light,虽能在预览视图里良好的显示正常、粗体、斜体、下划线等,但部署到应用后部分功能无效果,只能以正常字体显示。
如需完整使用以上的功能,需要装中文字体包导入到iReprot软件里去。
步骤如下:
安装字体:在菜单工具(tools)---->选项--->iReport---->fonts--->installfonts--->browse--->选择中文字体文件(simfang.ttf)
中文字体文件可以在系统文件夹 C:\WINDOWS\Fonts 找到你需要的字体。这里以 仿宋_GB2312 为例,如图选择相应的值。
--->下一步--->下一步--->下一步--->完成
这时在Fonts窗口中可以看到刚安装的字体了。
导出字体:选中刚安装的字体----Export as extension将刚导入的字体打包成*.jar文件导出。
根据个人习惯,我把它放在 C:\Program Files\Jaspersoft\iReport-4.1.1\ireport\fonts 文件夹下。
引用字体:切换到Classpath选项卡下,add jar---->找到刚导出的字体包将其导入,并勾上Reloadable。
这样我们就在iReprot里面可以用这个字体了。
使用字体时应注意
以调色板中的staticText为例:向页面上拖放一个staticText组件选中此组件,在属性窗口中找到如下几个属性
1,Font name 选择安装字体时所显示的名称,这里我选择的是仿宋_GB2312
2.PdfFontName, PdfEncoding, PdfEmbedded这三个属性全部清除。只需设置Font name一个即可。具体如下:
点击打开链接
If you have packed your TTFs in a font extension JAR, there is no reason for using the pdfFontName attributes in your JRXML.
Please remove them and make sure text fields have fontName, or have the fontName be inherited from a report default style.
Note that the three attributes pdfFontName, pdfEncoding, and isPdfEmbedded are now deprecated (replaced by settings inside font extensions).
I have tested your report and font extension JAR with iReport and it worked. Are you sure your font extension JAR is in the classpath at the time the PDF export is performed?
Is the PDF export occurring inside the same application that does the report filling?
注意。每一个要显示中文字体的组件都需要这样设定。这样就大功告成。
在应用程序中,同样需将导出的字体jar包放入classpath文件夹下。
实际上,按照以上的步骤完成后,在应用中仍然会报错FontFormatException。此问题困扰我很久很久。
最后发现在ireport 4.1.1版本中,使用Export as extension导出的字体jar包根本无法使用。里面的simfang.ttf文件大小竟然为0字节。不知道到底是谁的错误导致的。
无奈之下,手动将原始大小的simfang.ttf替换掉它。这才万事大吉。
相关文章推荐
- ireport引入到项目无法解析字体及pdf无法显示中文的解决方案
- 报表常见问题(二)ireport引入到项目无法解析字体及pdf无法显示中文的解决方案
- jasperreports和Ireport导出PDF文件中文不显示问题(最新解决方法)
- Jasperreports以及iReport4.5报表PDF导出字体完美解决方案
- dokuwiki + dw2pdf 插件,解决导出pdf文件中文乱码(字体问题,显示小方块)
- 集成到web项目之后,导出PDF时,中文无法正常显示或找不到中文字体
- jasperreport ireport PDF中文字体完美解决方案
- ireport导出中文pdf
- 关于iReport5.0导出PDF时的中文处理问题
- JasperReports iReport导出PDF中文解决办法
- ireport导出PDF中文处理方法
- jfreechart一&二维报表导出为word&pdf&html-中文乱码和字体模糊问题(一)
- jasperreport ireport创建PDF中文字体问题终极解决方法
- 对itext导出PDF的一些小总结,以及ireport中生成中文PDF
- Jaspersoft iReport Designer 4.7.0 导出pdf 中文不显示的解决办法
- [iReport总结1]iReport生成PDF文件中时的中文日文字体问题
- Ireport导出Pdf中文不显示
- jasperreport导出PDF中文不显示的问题
- android studio编程时引入外部字体样式
- css引入外部字体