My PDF generated by DynamicJasper now looking exactly as it's supposed to, I am facing only one more problem: Asian characters are not displayed at all in the resulting PDF. Any other characters work fine. I can verify in the debugger that the Strings are properly placed in the JRDataSource, and Jasper does in fact generate lines for them in the report, but the text itself is completely missing.
Are there some additional encoding settings to be considered when using DynamicJasper with Asian text elements?
Thanks for any advice and best regards
Okay, so this is what fixed the issue, step by step:
1.) Add the Arial Unicode MS font extension JAR to your classpath (or any other equivalent unicode font). An "official" one can be found here, I ended up using this one, however. If you're using maven, you can use the following mvn
command line and POM entry to add the file to your classpath:
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.) Add, if not already present, spring-core and spring-beans to the project:
<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.) Enable "Identity-H" Jasper PDF encoding:
static {
JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Identity-H");
}
4.) Configure Arial Unicode MS
as your DynamicJasper font (e.g. for rows):
// ...
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);
// ...
That was some annoying crap :-/ ...