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.
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 :)
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
[email protected]
[email protected]
Thank you. I have sent you
Thank you. I have sent you the mail with screenshots.
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:
Hi, I followed above
Hi,
I followed above mentioned steps but no luck .
However no errors reported .
thanks
Shrikanth
Kindly share your email id to
Kindly share your email id to me so that I can send my screenshots to you.
Thanks
Shrikanth
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
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 . . .
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)