I have a unique case where I have a Logo on the PageHeader Band of Jasper and I was expecting that since it is on the Page header, it should be printed on every page but it is getting printed only on the first Page. Same Jrxml is generating logo on all pages if I run it from ireport designer, but on my Java application, it is generating the logo only on the first page. Is there anything I am doing wrong?
My Java method:
public void formatreport(String foracid, String reportDir, String fromdate, String todate, String currdate, int pid, String suffix) {
Connection conn = null;
try {
conn = db.prepareConn();
Map parameters = new HashMap();
ClassLoader classLoader = getClass().getClassLoader();
InputStream logourl = classLoader.getResourceAsStream("/com/sim/bulk/jrxml/logo.jpg");
parameters.put("account", foracid);
parameters.put("from_date", fromdate);
parameters.put("to_date", todate);
parameters.put("period_id", pid);
parameters.put("suffix", suffix);
parameters.put("logo", logourl);
log.debug("Bulk statement Parameters: account:" + foracid + "\nfrom_date:" + fromdate + "\nto_date:" + todate + "\nperiod_id:" + pid);
InputStream url = classLoader.getResourceAsStream("com/sim/bulk/jrxml/Bulkstatement.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(url);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
reportDestination = reportDir + "/Statement_" + foracid + "_" + currdate + ".pdf";
JasperExportManager.exportReportToPdfFile(jasperPrint, reportDestination);
} catch (JRException asd) {
log.fatal(asd.getMessage());
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException asd) {
System.out.println(asd.getMessage());
}
}
}
and the extract from the jrxml:
<pageHeader>
<band height="162" splitType="Stretch">
<image onErrorType="Blank" evaluationTime="Now">
<reportElement uuid="a49076f0-b945-4742-bb15-737b2a927da2" x="12" y="12" width="74" height="50"/>
<imageExpression><![CDATA[$P{logo}]]></imageExpression>
</image>
</band>
</pageHeader>
Set isUsingCache="true" for the image. Otherwise the image would try to read the data from the input stream several times, which doesn't work.
Alternatively you can directly use the resource path ("/com/sim/bulk/jrxml/logo.jpg") as image expression, in most cases JasperReports would be able to load it from the classloader.