Jump to content
Changes to the Jaspersoft community edition download ×

How to add dynamic image in jasper report using jasper studio


tstuser
Go to solution Solved by tstuser,

Recommended Posts

How to add dynamic image in jasper report using jasper studio

Database is postgresql

image is stored in bytea format

how to display that image in jasper report.

i used the following query to retrieve image from db in text format

select encode(image,'escape') as img,id
from entity_image where id = 100

jasper source code is

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="image" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c591470d-2796-470b-a5ab-01b50ddf30b9">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="TST"/>
    <queryString language="SQL">
        <![CDATA[select encode(image,'escape') as image

 from entity_image where id = 100]]>
    </queryString>
    <field name="image" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="image"/>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <detail>
        <band height="125" splitType="Stretch">
            <image isUsingCache="true">
                <reportElement x="240" y="21" width="71" height="51" uuid="65f086cd-ae8e-46c5-ba66-85f3a9b0bc28"/>
                <imageExpression><![CDATA[new java.io.ByteArrayInputStream(org.apache.commons.codec.binary.Base64.decodeBase64($F{image}.getBytes()))  ]]></imageExpression>
            </image>
        </band>
    </detail>
</jasperReport>

it shows  net.sf.jasperreports.engine.jrexception: Image read failed .

How to solve this?? is there any other method?
 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...