Jasper Report – Chinese Language

<style name="Arial Unicode MS" isDefault="true" fontName="ArialUnicodeMS" fontSize="10" 
	pdfFontName="d:reportsARIALUNI.TTF" pdfEncoding="Identity-H" isPdfEmbedded="true"/>

It works fine with Chinese Language in Java or Uni Code.

JasperReports 3.6 Development Cookbook

I am one of the reviewers of this book from Packt Publishers.

JasperReports 3.6 Development Cookbook

JasperReports 3.6 Development Cookbook – Credits Page

It is really good book.

#jasperreports, #packt

Reports: Jasper Vs Apache POI Excel

After working with Jasper Reports….these are the points to remember while designing the reports.

1. Go for Jasper, only if it is required. Other wise better to use Apache POI Excel

Generally PDFs are read only. It is good to print invoices, bills, receipts, …etc

When there is a report with 40 pages, who is having time to print and read it.

If we use Apache POI  to write data to excel, it is easy to filter the data and do more drill down offline.


It is very difficult to format the report in Jasper Reports. It is easy to do in Excel.


We can off load the business logic to Excel and do in macros. This reduces burden on server side.

We can’t do in PDFs.


We can provide templates in Excel and we can import the data back from supervisor from a trip.

We can’t do this in PDFs.


Conclusion: User Jasper Reports, only if it is required. Other wise easy to complete same stuff with Apache POI Excel API.


Problem with Apache POI Excel API, client’s must need to have Windows and MS Office to read the documents.


Also better to use http://www.displaytag.sf.net to show data in tabular view.
1. user can sort the data easily.
2. Easy to provide reports in footer.


Jasper Reports 3.7.3, JBoss 4.2.3, Java 1.6.21 upgrade Problem

Problem: When upgrading to Jasper Reports 3.7.3, JBoss 4.2.3, Java 1.6.21 upgrade Problem, got the following problem.

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/classes/application-context.xml]; nested exception is java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)

Solution: XML Parser is provided by JBoss and Java 1.6. Due to this we need to knock down it from deployment



Jasper Reports – Pie Chart Shadows

Problem: Getting ugly shadows around tiny pie charts.

Solution: In palette select Theme as “aegean”

We will get this following error

Caused by: net.sf.jasperreports.engine.JRRuntimeException: Chart theme ‘aegean’ not found.

We need to add to the pom file.

Maven is not pulling them from repository.
We need to install.

Note: Try to use the files comes with respective jar bundle. Otherwise we will get version related errors.

#aegean, #jasper-reports-pie-chart-shadows, #net-sf-jasperreports-engine-jrruntimeexception-chart-theme-aegean-not-found, #pie-chart-shadows

Jasper Reports Public Repository

Many of the public maven repositories dont have support for latest Jasper Reports.

Add the following to pom.xml file.


Problems: Still it wont download themes and fonts jars.

#jasper-reports, #jasper-reports-public-repository

Restlet – Read HTTP Headers

Problem: How to read HTTP Headers in Restlet? Also we need to get Date from HTTP Headers.

Series<Parameter> headers = (Series<Parameter>) getRequest().getAttributes().get("org.restlet.http.headers");
Set<String> headerNames = headers.getNames();
for(String headerName:headerNames)
	System.out.println( "name==>"+headerName+" value==>"+ headers.getFirstValue(headerName));


name==>accept-encoding value==>gzip,deflate
name==>connection value==>keep-alive
name==>accept-language value==>en-us,en;q=0.5
name==>host value==>localhost:8080
name==>accept-charset value==>ISO-8859-1,utf-8;q=0.7,*;q=0.7
name==>user-agent value==>Mozilla/5.0 (Windows; U; Windows NT 4.x; en-US; rv:1.x.x.x) Gecko/23423423 Firefox/2.4.6
name==>accept value==>text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
name==>keep-alive value==>300

Observation: Date is missing when tried from Browser.

When tried from Restlet Client, it is working.

Form attributes = new Form();  
attributes.add( "message.date", "Mar-03-2010 10:30 AM" );
request.getAttributes().put( "org.restlet.http.headers", attributes );

Final Solution:
It is difficult to depend on HTTP Headers when clients are from Flex and other applications.
Easiest way is add Query String parameter like &date=123123123123123


#restlet, #restlet-http-headers

Setting JasperReports document properties

Problem Statement:  How to set JasperReports document properties?


net.sf.jasperreports.engine.JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
// Properties Begin
exporter.setParameter( JRPdfExporterParameter.METADATA_TITLE, "Title of the Document" );
exporter.setParameter( JRPdfExporterParameter.METADATA_AUTHOR, "Author of the document" );
exporter.setParameter( JRPdfExporterParameter.METADATA_SUBJECT, "Subject line of document" );
exporter.setParameter( JRPdfExporterParameter.METADATA_KEYWORDS, "Key Words to search down the line" );
exporter.setParameter( JRPdfExporterParameter.METADATA_CREATOR, "Application Name, which created this document." );
exporter.setParameter( JRPdfExporterParameter.OUTPUT_FILE_NAME, "Used when click on save button from client" );

//This used to set document passwords and compression and encryption
JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_USER_PASSWORD, "password1" );
JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_OWNER_PASSWORD, "password2" );
JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_ENCRYPTED, true );
JRProperties.setProperty( JRPdfExporterParameter.PROPERTY_COMPRESSED, true );

ByteArrayOutputStream out  = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);

Reference: Check
1. Jasper Reports API: http://jasperreports.sourceforge.net/api/index.html
2. Jasper Reports Forum
3. Samples: http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/samples.html


#jasper-reports-pdf-document-properties, #setting-jasperreports-document-properties

JasperReports – conditionalStyle

Problem: How to add colors based on project Status?
Like complete – Green, notcomplete – Red, other – None

Solution: Need to use conditionalStyle

<style name="style_name1" 
		<conditionExpression><![CDATA[new Boolean ($F{projectStatus}.equals("complete"))]]></conditionExpression>
		<style forecolor="#008B45" />
		<conditionExpression><![CDATA[new Boolean ($F{projectStatus}.equals("notcomplete"))]]></conditionExpression>
		<style forecolor="#FF0000" />
		<conditionExpression><![CDATA[new Boolean ($F{projectStatus}.equals("other"))]]></conditionExpression>


CSS Colors Chart : http://www.somacon.com/p142.php
Style Generator for Jasper: http://www.langtags.com/xmlsnippets/jasperreport/style.html

#conditionalstyle, #jasperreports-conditional-style, #jasperreports-conditionalstyle

JasperReports – Style

Problem: How to prepare style for Jasper Report Elements?

Style Generator http://www.langtags.com/xmlsnippets/jasperreport/style.html

JasperReports UI Tools

Jasper Assistant http://www.jasperassistant.com/
iReport http://jasperforge.org/projects/ireport

#jasperreport-style, #jasperreport-ui