Right Outer Join

13 May 2009

Fonts in JasperServer

Filed under: JasperServer — Tags: , , , , , , — mdahlman @ 18:00

Article updated

Most folks should refer to my updated article on Fonts in JasperServer 3.7 instead of the article below. But I’m leaving the old article here for cases where someone needs to run the older version of JasperServer.

JasperServer 3.5.1 released

JasperServer Professional 3.5.1 from Jaspersoft will be released shortly. One of the more anticipated features for me will be the inclusion of a localized Chinese GUI. I got a sneak peek at it this morning. The menus and user interface are completely in Chinese (if I choose the appropriate locale). Hooray! But I ran one of the sample reports, and this is what I saw:

The report is not completely localized

The report is not completely localized

What’s wrong with this picture? The text that stands by itself is fine, but the text that gets rendered as part of the chart image doesn’t display correctly at all. How can this be? Everything is Java-based, so I shouldn’t have localization issues. The problem is that the report specifies Verdana as its font for nearly everything, but Verdana doesn’t include support for Chinese characters. (Interestingly, the text that displays well was also specified as Verdana. But the browser realizes the specified font doesn’t have the correct characters, so it automatically substitutes another font. It’s a useful feature, but it made understanding the underlying problem more difficult.) The solution is to select appropriate fonts.

Fixing the fonts

Fortunately it’s not any sort of JasperServer bug; it’s just an issue with the sample reports. Now that I see what’s causing the problem, it should be easy to fix:

  1. Update the report to use an appropriate font
  2. Deploy the font to JasperServer

Updating the report should be easy. Open iReport, connect to JasperServer, get the reports, set the font. But the devil is in the details. The sample report with the problem is/supermart/salesByMonth/SalesByMonthReport. I open it, find the chart, find the property “Legend font” and see that the current font is “Verdana”. I change this to “Arial Unicode MS”. I save the report back to JasperServer and see what it looks like now. No change. This isn’t be surprising because the server doesn’t have the font in its classpath anywhere.

I’ve never deployed a font to JasperServer before. So it took a little poking around in the documentation and the samples to see what was needed. The key concept is the need for JasperReports Font Extensions. The JasperReports Ultimate Guide has a good explanation and tutorial, so I was off to a good start. Three files are needed:

  1. jasperreports_extension.properties
  2. fonts.xml
  3. The actual font file (This might be multiple files… but in my case it was just one.)

All of the files need to be in the Java classpath, so this is a good place to put them given that I’m using Apache Tomcat: …\Tomcat 5.5\webapps\jasperserver-pro-3.5\WEB-INF\classes


The name of this file is important. JasperReports knows to load the file based on its name. Its contents are simple. I copied it unmodified from the documented example:



This file can take any name; it just needs to match what is specified above. The contents are only minimally updated from the sample provided:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 <bean id="myFontFamily" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
   <property name="name" value="Arial Unicode MS"/>
   <property name="normal" value="fonts/ARIALUNI.TTF"/>
   <property name="pdfEncoding" value="Identity-H"/>
   <property name="pdfEmbedded" value="true"/>

I chose the font Arial Unicode MS because it includes Chinese characters, and it ships with MS Office. There are other downloadable fonts available for people that don’t have access to this one.

The font file(s)

In fonts.xml the font file is specified as fonts/ARIALUNI.TTF. I did this so I could put all of my fonts into a subdirectory under the classes directory. I’m using default locations for everything, so this was the copy command:

copy C:\WINDOWS\Fonts\ARIALUNI.TTF "C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\jasperserver-pro-3.5\WEB-INF\classes\fonts"

Enjoy the corrected reports

After restarting JasperServer, the report now looks like this:

Now everything is correctly localized into Simplified Chinese

Everything is correctly localized into Simplified Chinese

The process is simple, but it’s not entirely intuitive. And you need to get things exactly right. Hopefully this will be an aid to anyone encountering localization issues with the charts (JFreeChart) in JasperServer.

Additional Details

I described the step-by-step process only for the chart legend. But there are a few more properties that need to be set for anyone that wants the complete demo dashboard to display correctly.

In the report /supermart/salesByMonth/SalesByMonthReport you need to set both the “Legend font” and the “Category Axis Tick Label Font”. There are two charts (one on top of the other), so be sure to set both properties for both charts.

In the report /supermart/revenueAndProfit/SalesGaugesReport it’s the “Value Font” that needs to be changed. This property should be set for all four dial gauges.



  1. I’m trying to modify the Supermart Demo SalesByMonth Report to change the labels that are all pulled in by resource.

    I’ve tried changing the supermart.properties file and supermart_en_US.properties file in two different locations in the repository.

    Any idea where JS is pulling the supermart resources from in the default sample install?

    Comment by Steve — 1 July 2009 @ 00:48

    • I’ll give the full urls to avoid confusion. You want to change this report:

      It refers to this file:
      (and supermart.properties, supermart_de.properties, etc. in the same folder)

      If you change that properties file, you should see the changes in the report. I can imagine there might be a problem with caching: if JasperServer doesn’t detect that there has been any change to the report, then it will use its already-compiled report. So it might not pick up the modified properties file. (I’ve never heard of a problem like this… I’m just speculating.)

      To confirm that nothing funny like that is happening you could make a minor tweak to the report to force a recompilation.

      If you’re still having troubles, please post to the JasperServer forum here: http://jasperforge.org/projects/jasperserver/forum.

      Comment by mdahlman — 2 July 2009 @ 11:02

  2. Thank you so much for your article.

    After switching to jasperreport 3.6.1, I have finally got my old reports to work with chinese characters based on your method.

    If only the JR Ultimate guide would contain this kind of info…

    Comment by Patrick Tan — 9 November 2009 @ 00:32

  3. i’m facing one problem. The fonts i have added for PDF encoding its not working? i was not able to figure it out? how do i solve this font problem?

    Comment by Ravi — 23 November 2009 @ 03:54

    • Ravi,
      That’s not much detail to be able to make a guess about what’s happening. Please post this question to the forums on jasperforge.org. Please add some details about what exactly you did and what results you are seeing.

      Comment by mdahlman — 23 November 2009 @ 10:08

  4. Thanks for the very good post!

    Comment by Clement Lee 李锐华 — 10 March 2010 @ 12:23

  5. […] Shared Fonts in JasperServer « Right Outer Join. […]

    Pingback by Frau Klein during the week in the interweb | Frau Klein — 14 March 2010 @ 18:36

  6. […] Shared Fonts in JasperServer « Right Outer Join. […]

    Pingback by Frau Klein im Internet during the week | kerstins kleiner blog — 15 March 2010 @ 12:04

  7. […] have written about fonts in JasperServer in the past, but I’m revisiting it now. It’s popular topic because fonts are very […]

    Pingback by Fonts in JasperServer 3.7 « Right Outer Join — 16 April 2010 @ 12:05

  8. Thanks Matthew. Your post was really helpful!

    Comment by Daniel Góis de Oliveira Gomes — 7 May 2010 @ 13:52

  9. […] down (or creating) the relevant XML files, properties files, and TTF font files. I wrote about font extensions in JasperServer 3.5 previously. In JasperServer 3.7 it’s a single click to export the extension and only a few […]

    Pingback by Jaspersoft v3 Font Extensions « Right Outer Join — 28 May 2010 @ 14:38

  10. […] found an interesting blog post Fonts in JasperServer about providing custom fonts. The author is configuring the font extensions using Spring. However, […]

    Pingback by Use custom fonts in JasperReports PDF exporter « Marcin Gryszko, freelance software developer — 1 June 2010 @ 13:10

  11. Excellent !! Matthew.

    Comment by mork — 26 July 2011 @ 08:38

  12. Could you do an article on using Pro Charts (FusionChart) in iReport? I love the charts article you did, but I use the Pro Charts more often and would appreciate any insight into using them. Thanks!

    Comment by Mike — 28 February 2012 @ 15:02

    • Mike, sorry for my slow response to your comment. Thanks for your kind words. I’m not opposed to an article about the Pro Charts and Widgets, but it’s not too likely. I haven’t worked with them a lot. I made a sparkline I was pleased with, but I’m not sure it has wide applicability to others. On the other hand, there is work underway to incorporate some highly polished JavaScript charts into the Ad Hoc report designer. I’m very excited to use and write about that when it comes.

      Comment by mdahlman — 16 March 2012 @ 08:49

RSS feed for comments on this post. TrackBack URI

Go on... leave a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: