好的,这就是逐步解决问题的方法:
1.) 将 Arial Unicode MS 字体扩展 JAR 添加到您的类路径(或任何其他等效的 unicode 字体)。可以在here 找到一个“官方”,但是我最终使用了this one。如果您使用的是 maven,则可以使用以下 mvn 命令行和 POM 条目将文件添加到您的类路径:
mvn install:install-file -Dfile=DynamicJasper-arial-unicode-fonts-1.0.jar -DgroupId=ar.com.fdvs -DartifactId=DynamicJasper-arial-unicode-fonts -Dversion=1.0 -Dpackaging=jar
<dependency>
<groupId>ar.com.fdvs</groupId>
<artifactId>DynamicJasper-arial-unicode-fonts</artifactId>
<version>1.0</version>
</dependency>
2.) 将 spring-core 和 spring-beans 添加到项目中(如果尚未存在):
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
3.) 启用“Identity-H”Jasper PDF 编码:
static {
JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Identity-H");
}
4.) 将 Arial Unicode MS 配置为您的 DynamicJasper 字体(例如,用于行):
// ...
final DynamicReportBuilder dynamicReportBuilder = new DynamicReportBuilder();
final Style style = new Style();
style.setFont(new Font(Font.MEDIUM, "Arial Unicode MS", false));
dynamicReportBuilder.setDefaultStyles(null, null, null, style);
// ...
那是一些令人讨厌的废话:-/ ...