Jasper Reports – Fields And Fonts On Different Operating Systems

Jasper Reports – Fields And Fonts

I have been using Jasper Reports for a while and an interesting senario came to light. This is to do with fields been truncated on linux systems when the report is generated.

For example if we generate a csv file and in the report we have a field as follows:

<textField isBlankWhenNull=”true”>
<reportElement x=”76″ y=”0″ width=”63″ height=”11″/>
<textElement>
<font size=”6″/>
</textElement>
<textFieldExpression class=”java.lang.String“>

<![CDATA[“‘” + $F{user_id}]]></textFieldExpression>
</textField>

The above generated a report in which the field user_id (which is 18 characters wide) displayed all 18 characters on Windows Vista but on linux it truncated the last two and we only had 16 characters displaying.

On researching the issue I found that this problem had in deed manifested itself in a few places on the internet.

I found out that the different ways each operating systems handles the fonts caused this problem.

Increasing the width solved this partially:

<textField isBlankWhenNull=”true”>
<reportElement x=”76″ y=”0″ width=”70″ height=”11″/>
<textElement>
<font size=”6″/>
</textElement>
<textFieldExpression class=”java.lang.String“>

<![CDATA[“‘” + $F{user_id}]]></textFieldExpression>
</textField>

However another problem came to light and this was that on different versions of SUSE the generated report appeared differently.

On one version it printed correctly yet on another it still truncated the field.

When running a uname -arv on the machine that worked we have:

admin: uname -arv
Linux xserver1 2.6.5-7.257-nh1 #4 SMP Tue Jun 6 15:45:06 SAST 2006 i686 i686 i386 GNU/Linux

When running uname -arv on the machine that didn’t work we have:

admin: uname -arv
Linux xserver2 2.6.5-7.244-xeon #3 SMP Tue Nov 28 14:18:50 SAST 2006 i686 i686 i386 GNU/Linux

Seems the differences in the build version of the kernel make a difference which is an interesting observation .

The problem was resolved by extending the width once again:

<textField isBlankWhenNull=”true”>
<reportElement x=”76″ y=”0″ width=”87″ height=”11″/>
<textElement>
<font size=”6″/>
</textElement>
<textFieldExpression class=”java.lang.String“>

<![CDATA[“‘” + $F{user_id}]]></textFieldExpression>
</textField>

 

This time it worked on all three machines.

Advertisements

About gjcbell

I'm a software designer and integration specialist in Cape Town, South Africa. I work for SPF at SGH. I develop applications in Java, Cplusplus and Python and JavaScript. I design websites and web applications.
This entry was posted in Computers and Internet, Java programming, JavaScript, Uncategorized. Bookmark the permalink.

One Response to Jasper Reports – Fields And Fonts On Different Operating Systems

  1. Pingback: Jasper Reports – Fields And Fonts On Different Operating Systems

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s