DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Jasper Reports – Fields And Fonts On Different Operating Systems

Gabriel Campbell user avatar by
Gabriel Campbell
·
Apr. 01, 11 · Interview
Like (0)
Save
Tweet
Share
10.22K Views

Join the DZone community and get the full member experience.

Join For Free

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.

 

From http://gabrieljeremiahcampbell.wordpress.com/2011/03/31/jasper-reports-fields-and-fonts-on-different-operating-systems/

JasPer

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Create a CLI Chatbot With the ChatGPT API and Node.js
  • Asynchronous Messaging Service
  • Building a RESTful API With AWS Lambda and Express
  • [DZone Survey] Share Your Expertise and Take our 2023 Web, Mobile, and Low-Code Apps Survey

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: