How to display an image from PostgresSQL with iReport 5.5.0

I'm using iReport 5.5.0. I would like to display images store as byte array in Postgres on my report. How can i do that?

massi.b's picture
Joined: Dec 16 2013 - 2:33am
Last seen: 8 years 8 months ago

1 Answer:

It's something like:

new ByteArrayInputStream(new Base64().decodeBase64($F{Image}.getBytes("UTF-8")))</div>
<p style="margin-top: 0px; margin-bottom: 10px; color: rgb(85, 85, 85); font-family: Verdana, 'BitStream vera Sans', Helvetica, sans-serif; line-height: 17.399999618530273px; background-color: rgb(255, 255, 255);">(don’t forget to add <code style="margin: 0px; padding: 0px;"><a href="http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html" sl-processed="1" style="color: rgb(41, 112, 166);" target="_blank">org.apache.commons.codec.binary.Base64</a> to the imports of the report properties)</p>
<p style="margin-top: 0px; margin-bottom: 10px; color: rgb(85, 85, 85); font-family: Verdana, 'BitStream vera Sans', Helvetica, sans-serif; line-height: 17.399999618530273px; background-color: rgb(255, 255, 255);">and in the image element on your layout use the ImageBytes variable:</p>
<div style="margin: 20px; color: rgb(85, 85, 85); font-family: Verdana, 'BitStream vera Sans', Helvetica, sans-serif; line-height: 17.399999618530273px; background-color: rgb(255, 255, 255);"><a href="http://raygauss.files.wordpress.com/2009/12/jasper-image-element.png" sl-processed="1" style="color: rgb(41, 112, 166);"><img alt="" class="alignnone size-medium wp-image-319" height="67" src="http://raygauss.files.wordpress.com/2009/12/jasper-image-element.png?w=300&h=67" style="margin: 0px; padding: 0px; max-width: 600px;" title="jasper-image-element" width="300" /></a></div>
<div style="margin: 20px; color: rgb(85, 85, 85); font-family: Verdana, 'BitStream vera Sans', Helvetica, sans-serif; line-height: 17.399999618530273px; background-color: rgb(255, 255, 255);"> </div>
<div style="margin: 20px; color: rgb(85, 85, 85); font-family: Verdana, 'BitStream vera Sans', Helvetica, sans-serif; line-height: 17.399999618530273px; background-color: rgb(255, 255, 255);">(from: http://rgauss.com/2009/12/21/jasperreports-xml-datasource-with-inline-images/)</div>
ernestoo's picture
18046
Joined: Nov 29 2010 - 11:59am
Last seen: 5 years 5 months ago
Feedback
randomness