Jump to content
Changes to the Jaspersoft community edition download ×

display image in jasper report


mathewrond

Recommended Posts

Hi,

I have a XML file as Database and I am using xPath to read the xml file.

 

I am trying to display an image in the report and the xml file gives me a string value which I need to use and display the image.

 

The image is located in APP-INF/classes folder of .ear file.

 

Here is what I have tried and it doesn't display me the image.

 

Code:
				<image  evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
<reportElement
x="7"
y="6"
width="140"
height="40"
key="image-1"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<graphicElement stretchType="NoStretch"/>
<imageExpression class="java.lang.String"><![CDATA[$F{Logo}]]></imageExpression>
</image>

 

Is there a way to get the image displayed?

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

I read an XML file to get information so I use XPath to query the XML file.

 

 

<LOGO>logo.gif</LOGO> - tag in XML File

 

 

The value that I get from the XML file is

 

 

logo.gif

 

 

Below is my field and image tag in jrxml file

 

Code:

<field name="Logo" class="java.lang.String">
<fieldDescription><![CDATA[//Logo]]></fieldDescription>
</field>

<image evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="7"
y="6"
width="140"
height="40"
key="image-1"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<graphicElement stretchType="NoStretch"/>
<imageExpression class="java.lang.String"><![CDATA[$F{Logo}]]></imageExpression>
</image>

 

 

My image is located in APP-INF/classes/logo.gif

 

 

I have placed all my .jasper files in the same APP-INF folder and I am able to load them in the java code.

 

 

But the image has to be loaded from .jasper file and I am not able to get it.

 

 

Regards,

Mathew

Link to comment
Share on other sites

No, I am not loading the image from the java code but I am loading .jasper files from APP-INF/classes/jasper/*.. and here is the code that I used for it.

 

Code:

InputStream designFormatInputStream = null;
designFormatInputStream = this.getClass().getClassLoader()
.getResourceAsStream("f1.jasper");
jasperReport = (JasperReport) JRLoader.loadObject(designFormatInputStream);

Post edited by: mathewrond, at: 2006/10/19 10:11

Link to comment
Share on other sites

My query was whether you could try to load the image from java code and see whether it works or not, maybe this would have helped finding the cause of the problem..

 

Anyway, you could try doing

Code:

params.put(JRParameter.REPORT_CLASS_LOADER, this.getClass().getClassLoader());

when filling the report, maybe this will help..

Link to comment
Share on other sites

  • 5 years later...

Hi,

         Please used the below mentioned code for Image Displaying. Please pass the argument with image name.

         Parameter name is "IMAGE_DIR".

 

HashMap<String,Object> jasperParameter = new HashMap<String,Object>();

jasperParameter.put("SUBREPORT_DIR",jrxmlSourceLocation);

jasperParameter.put("IMAGE_DIR",ImageDir);

if(reportFormat.equalsIgnoreCase(ReportConstansts.FORMAT_HTML) || reportFormat.equalsIgnoreCase(ReportConstansts.FORMAT_EXCEL)){

jasperParameter.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);

}

 

File fname = new File(destinationPath + FILE_SEPARATOR + filename+ReportConstansts.EXCEL_EXT);

JRXlsExporter jRXlsExporter = new JRXlsExporter(); 

jRXlsExporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); 

jRXlsExporter.setParameter(JRXlsExporterParameter.IS_IGNORE_CELL_BORDER,Boolean.TRUE); 

jRXlsExporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.FALSE); 

jRXlsExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE); 

jRXlsExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,Boolean.TRUE);

jRXlsExporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE,Boolean.TRUE);

jRXlsExporter.setParameter(JRXlsExporterParameter.OFFSET_X,0); 

jRXlsExporter.setParameter(JRXlsExporterParameter.OFFSET_Y,0); 

jRXlsExporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE,Boolean.TRUE);

jRXlsExporter.setParameter(JRXlsExporterParameter.JASPER_PRINT_LIST, jprintlist);

jRXlsExporter.setParameter(JRXlsExporterParameter.SHEET_NAMES,ReportConstansts.TAB_NAMES);

jRXlsExporter.setParameter(JRXlsExporterParameter.OUTPUT_FILE_NAME,fname.toString());

try {

jRXlsExporter.exportReport();

} catch (JRException ex) {

logger.log(ILogger.LEVEL_SEVERE,"Exception occured while exporting the JasperReport:"+ex.getMessage(),null,ex);

          

   }

Thanks,

 

 

Bhooppandra

 

 

Code:
<?xml version="1.0" encoding="UTF-8"?><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="Topology" language="groovy" pageWidth="650" pageHeight="750" columnWidth="0" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">	<property name="ireport.zoom" value="1.0"/>	<property name="ireport.x" value="0"/>	<property name="ireport.y" value="0"/>	<parameter name="IMAGE_DIR" class="java.lang.String"/>	<background>		<band splitType="Stretch"/>	</background>	<title>		<band splitType="Stretch"/>	</title>	<pageHeader>		<band splitType="Stretch"/>	</pageHeader>	<columnHeader>		<band height="30" splitType="Stretch"/>	</columnHeader>	<detail>		<band height="650" splitType="Stretch">			<image isLazy="true" scaleImage="RealHeight">				<reportElement  x="0" y="0" width="500" height="650"/>				<imageExpression><![CDATA[$P{IMAGE_DIR}]]></imageExpression>			</image>		</band>	</detail>	<columnFooter>		<band splitType="Stretch"/>	</columnFooter>	<pageFooter>		<band splitType="Stretch"/>	</pageFooter>	<summary>		<band splitType="Stretch"/>	</summary></jasperReport>
Link to comment
Share on other sites

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...