2

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

Alfabravo
  • 7,493
  • 6
  • 46
  • 82
Pascal Kesseli
  • 1,620
  • 1
  • 21
  • 37

2 Answers2

7

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 :-/ ...

Pascal Kesseli
  • 1,620
  • 1
  • 21
  • 37
0

you may have to configure jasper report exporter to embed special fonts on the pdf file. also check ck the pdf character encoding

Dj Mamana
  • 339
  • 1
  • 8
  • Hi Dj, thanks for you input. PDF font embedding was not necessary, as it seems. It's just that I tried both the unicode font as well as the "Identity-H" encoding, just not at the same time :-S . – Pascal Kesseli Apr 12 '13 at 11:18
  • I found that embedding is actually necessary if a PDF is generated. Adding Unicode font as dependency AND Identity-H encoding works for the in-screen presentation but the PDF needs the font to be included. – Alfabravo Mar 23 '16 at 16:31