<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>redstream &#187; jasperserver</title>
	<atom:link href="http://www.redstream.nl/tag/jasperserver/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redstream.nl</link>
	<description>Pragmatic Integrators</description>
	<lastBuildDate>Fri, 27 Jan 2012 19:31:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Solving the JasperServer TrueType Font Issue</title>
		<link>http://www.redstream.nl/2010/05/31/solving-the-jasperserver-truetype-font-issue/</link>
		<comments>http://www.redstream.nl/2010/05/31/solving-the-jasperserver-truetype-font-issue/#comments</comments>
		<pubDate>Mon, 31 May 2010 21:16:56 +0000</pubDate>
		<dc:creator>Pascal Prins</dc:creator>
				<category><![CDATA[Jasper Reports]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[jasperreports]]></category>
		<category><![CDATA[jasperserver]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1807</guid>
		<description><![CDATA[Currently I&#8217;m finalizing a reporting solution based on JasperReports. The solution includes a JasperServer instance running on Linux. After deploying some initial reports to JasperServer using iReports I noticed that the TrueType fonts used when designing the reports (on Windows) &#8230; <a href="http://www.redstream.nl/2010/05/31/solving-the-jasperserver-truetype-font-issue/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F05%2F31%2Fsolving-the-jasperserver-truetype-font-issue%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F05%2F31%2Fsolving-the-jasperserver-truetype-font-issue%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Currently I&#8217;m finalizing a reporting solution based on <a href="http://jasperforge.org/projects/jasperreports">JasperReports</a>. The solution includes a JasperServer instance running on Linux. After deploying some initial reports to <a href="http://jasperforge.org/projects/jasperserver">JasperServer</a> using <a href="http://jasperforge.org/projects/ireport">iReports</a> I noticed that the TrueType fonts used when designing the reports (on Windows) did not render correctly. In fact, they did not render at all &#8230; JasperReports decided to use a default font instead.</p>
<p>From the JasperServer log it appeared that the font used in the report could not be found: &#8220;<code>JRFontNotFoundException: Font 'Courier New' is not available to the JVM</code>&#8221;
</p>
<p><span id="more-1807"></span></p>
<p>Using the following steps I fixed my font-issue (note: I&#8217;m a Linux kind-a guy, please translate the following steps to your own environment):</p>
<p>First, we&#8217;ll need to install the Microsoft TrueType fonts. Excellent reference here: <a href="http://corefonts.sourceforge.net">http://corefonts.sourceforge.net</a>. In short, the following steps apply:
<ul>
<li><code>sudo yum install rpmbuild cabextract</code></li>
<li><code>wget http://corefonts.sourceforge.net/msttcorefonts-2.0-1.spec</code></li>
<li><code>rpmbuild -bb msttcorefonts-2.0-1.spec</code></li>
<li>Find out where file <code>msttcorefonts-2.0-1.noarch.rpm</code> is located and do <code>rpm -ivh msttcorefonts-2.0-1.noarch.rpm</code></li>
</ul>
<p>Now the TrueType fonts are installed (use the <code>fc-list</code> command to display a list of fonts installed), we need to configure JasperServer so they can be used:</p>
<ul>
<li>Open a SSH session to the JasperServer machine and goto directory <code>$CATALINA_HOME/shared/classes</code>. I use this directory because its contents is by default on the classpath of Apache Tomcat (and that&#8217;s exactly where we need the following files) and its non-intrusive with regard to the JasperServer installation;</li>
<li>Create a file called <code>jasperreports_extension.properties</code> with the following contents (copied from the jasperreports demo directory):</li>
</ul>

<div class="wp_codebox"><table><tr id="p18073"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1807code3"><pre class="xml" style="font-family:monospace;">net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory
net.sf.jasperreports.extension.fonts.spring.beans.resource=fonts.xml</pre></td></tr></table></div>

<p>The contents of this file has been copied from the JasperServer documentation. Two things are important: the name of file (JasperServer expects it to be named like this and will automagically load it) and the reference to <code>fonts.xml</code></p>
<ul>
<li>Create a file called <code>fonts.xml</code> with the following contents:</li>
</ul>

<div class="wp_codebox"><table><tr id="p18074"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p1807code4"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">       <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans</span>
<span style="color: #009900;">       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;CourierNewFontFamily&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;net.sf.jasperreports.engine.fonts.SimpleFontFamily&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Courier New&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;normal&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/usr/share/fonts/msttcorefonts/cour.ttf&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;bold&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/usr/share/fonts/msttcorefonts/courbd.ttf&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;italic&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/usr/share/fonts/msttcorefonts/couri.ttf&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;boldItalic&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/usr/share/fonts/msttcorefonts/courbi.ttf&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;pdfEncoding&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Identity-H&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;pdfEmbedded&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><br/><br />
A few remarks:</p>
<ul>
<li>Note that the <code>name</code> property should reflect (exactly) the name of the font as used in your JasperReport. I used the name <code>Courier New</code>, because that&#8217;s what my exception said.</li>
<li>Properties <code>normal</code>, <code>bold</code>, etcetera, refer to the location of the font. By doing a <code>sudo find / -name *.ttf</code> on our LInux machine, we found out the location of the TTF font.</li>
<li>When using exotic fonts, the <code>pdfEmbedded</code> property can be used to embed the font into the PDF (actually, the property name itself gave that away). Your PDF will be somewhat larger in size, but the result will be readable.</li>
</ul>
<p>For a full reference of the possible properties, just check the <a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/fonts/SimpleFontFamily.html">JavaDoc</a> for <code>SimpleFontFamily</code>. Just remember that each FontFamily gets its own bean.<br />
<br/><br />
Now both files are in place, all we need to do now is restart JasperServer (read: Apache Tomcat). Once Tomcat has been restarted, run your report again and the fonts you were previously missing will be there.</p>
<p><strong>UPDATE:</strong> We just upgraded to <a href="http://jasperforge.org/index.php?q=project/jasperserver">JasperReports Server 4.1</a>. The solution described above has proven to work on this version as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/05/31/solving-the-jasperserver-truetype-font-issue/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

