mathewrond Posted October 18, 2006 Share Posted October 18, 2006 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 More sharing options...
mathewrond Posted October 19, 2006 Author Share Posted October 19, 2006 I have read in most of the forums that if the Image is in classpath then relative path should work. In my case the image is in classpath i.e. in APP-INF/classes folder. But why is it not getting loaded? Any ideas would be helpful. Link to comment Share on other sites More sharing options...
lucianc Posted October 19, 2006 Share Posted October 19, 2006 Can you give a concrete example of an image location under APP-INF/classes and the image expression you are using? Link to comment Share on other sites More sharing options...
mathewrond Posted October 19, 2006 Author Share Posted October 19, 2006 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 More sharing options...
lucianc Posted October 19, 2006 Share Posted October 19, 2006 Are you able to load the image from your java code? If so, can you post the code you use to load it? Link to comment Share on other sites More sharing options...
mathewrond Posted October 19, 2006 Author Share Posted October 19, 2006 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 More sharing options...
lucianc Posted October 19, 2006 Share Posted October 19, 2006 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 doingCode:params.put(JRParameter.REPORT_CLASS_LOADER, this.getClass().getClassLoader());when filling the report, maybe this will help.. Link to comment Share on other sites More sharing options...
mathewrond Posted October 19, 2006 Author Share Posted October 19, 2006 Hi,Thanks for the suggestion. I have tried by putting the extra parameter before fill but I still am not able to see the image. I will try your other suggestion of loading the image from java code and see if it helps. Regards,Mathew Link to comment Share on other sites More sharing options...
bhooppandra_jat Posted July 26, 2012 Share Posted July 26, 2012 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now