India

ZestyBeanz Technologies Pvt Ltd 4th Floor, Nila, Technopark Thiruvananthapuram,
India – 695581
Phone: +91 471 4063254
Fax : +91 471 2700171

   .

ZestyBeanz Technologies Pvt Ltd
61/3236, Manikkath Cross Road
Ravipuram, Kochi, India - 682016
Phone: +91 484 4063254

  UAE

Zesty Labs
Office # 2003, Millennium Plaza Building
Sheikh Zayed Rd, Dubai, UAE
Phone: +971 4333 2222​
Mobile: +971-52-7553466

  Germany​

ZestyBeanz Technologies GmbH
Reuterstraße 1
90408 Nürnberg
Fon: +49 911 4801 444
Fax: +49 911 4801 445

Dynamic Image From Database in Jasper Report

Contact Form


Prajul P T's picture

Dynamic Image From Database in Jasper Report

   When dealing with internal documentation in a company, images plays an important role. For example, company logo is a must in most of the documentation in a company. Here I am going to explain how to create dynamic images in jasper report fetched from the database.

   I am using iReport 4.7.1 with OpenERP. In my report I am passing the image to the report as a parameter. I have created a parameter in iReport as "logo" which holds image data passed from the python to the report. In python side, i am fetching my logo as: 

and passed to report as a parameter "logo". The variable class of logo should be  "java.lang.String".

   In report add a Report Import directive "org.apache.commons.codec.binary.Base64". To do that in iReport, right click on the report and go to "Properties" at the end you can see "Imports" as shown below:

Add the entry to it. Now create a variable say "photo"  with "Variable class" as "java.io.InputStream", "Calculation" as "Nothing", "Reset Type" as "Report" and "Variable Expression" as:

new ByteArrayInputStream(new Base64().decodeBase64($P{logo}.getBytes("UTF-8")))

where $P{logo} is the parameter created earlier which contain image data.

   Now drag and drop the image component from the pellet window. When the windows prompt to select the image, press cancel. Now in "Image Expression" field, add the variable $V{photo} created before and "Expression Class" as "java.io.InputStream". If you are intending to put the logo in title band, set evaluation time to "Report". Now the report should be printed with logo from the database.

Anonymous's picture

Thanks for your post! I

Thanks for your post!
I wannted this dynamic image in my report!
I didn't know how to do that. Now I got it.
I appreciate you :)

shrikanth's picture

Hello, Followed the above

Hello,

Followed the above mentioned steps for my openerp/ireport project.

Unfortunately couldn't get image on to report. However no errors are been reported

Anonymous's picture

[email protected]

shrikanth's picture

Thank you. I have sent you

Thank you. I have sent you the mail with screenshots.

Prajul P T's picture

Hi,    I found the issue.

Hi,

   I found the issue. The problem is if the data is not present ie; if the query in the report returns no data in ireport, the variables in the ireport will not be executed. So what i did is:

  1. Moved the Image pallet to Title band
  2. Changed "When No Data" property of the report to "All Sections, No Detail"
  3. In Image pellet property, changed "Image Expression" to "new ByteArrayInputStream(new Base64().decodeBase64($P{logo}.getBytes("UTF-8")))"
shrikanth's picture

Hi, I followed above

Hi,
I followed above mentioned steps but no luck .

However no errors reported .

thanks
Shrikanth

shrikanth's picture

Kindly share your email id to

Kindly share your email id to me so that I can send my screenshots to you.

Thanks
Shrikanth

shrikanth's picture

Hi, I have followed above

Hi,

I have followed above mentioned steps.Unfortunately I couldnot see my images in ireport. However no errors encountered. It will be great if you provide me your email id so that I can send you screenshots . Appreciated your help

Kyaw Sint's picture

I'm using iReport 5.0.1. I

I'm using iReport 5.0.1. I can't show dynamic image with pdf format using ireport and jasper report in openerp. I have been tested above you say but doesn't work. And then my iReport doesn't work preview. I click preview button 'null message box' show. So how can i show dynamic image and work ireport preview button. Thaks you! Waiting for your reply . . .

MuraliKrishnaReddy's picture

I am using the iReport4.0.2

I am using the iReport4.0.2 and when i did the above things and try to create a variable, i got an Error as :

Error filling print... Error evaluating expression :      Source text : new ByteArrayInputStream(new Base64().decodeBase64($F{logo_web}.getBytes("UTF-8")))
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :      Source text : new ByteArrayInputStream(new Base64().decodeBase64($F{logo_web}.getBytes("UTF-8")))
.
.
.
Caused by: groovy.lang.MissingMethodException: No signature of method: [B.getBytes() is applicable for argument types: (java.lang.String) values: [UTF-8] Possible solutions: getAt(java.lang.String), getClass(), getAt(groovy.lang.IntRange), getAt(java.lang.Integer), getAt(groovy.lang.ObjectRange), getAt(java.util.Collection)