I developed a jasper report using the ireport constructor, in which I added a logo in the report header. This image is added from a hard-coded path on the local computer. I need to add a logo image from my classpath class. To do this, I created a parameter for the image in the report that comes from the program.
InputStream imgInputStream = this.getClass().getResourceAsStream("header.png"); HashMap<String, Object> parameters = new HashMap<String, Object>(); parameters.put("dateFrom", datum1); parameters.put("dateTo", datum2); parameters.put("logo", imgInputStream); strQuery = "Select calldate,src,dst,duration,disposition,cdrcost from cdrcost where date(calldate) between '" + datum1 + "' and '" + datum2 + "'"; rs = conexiondb.Consulta(strQuery); JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource(rs);
And below is a snippet of the image from the report:
<image> <reportElement x="0" y="1" width="555" height="61"/> <imageExpression><![CDATA[$P{logo}]]> </imageExpression> </image>
source share