我使用ireport設計器設計了一個jasper報告,其中我在報告的標題中添加了徽標圖像。該圖像是從本地機器上的硬編碼路徑添加的。我需要從我的項目類路徑中添加徽標圖像。爲此,我在程序提供的報告中爲圖像創建了一個參數。如何添加圖像作爲jasper報告中項目classpath的參數
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);
//JasperPrint jasperPrint = JasperFillManager.fillReport(reportStream, parameters);
JasperRunManager.runReportToPdfStream(reportStream, fos, parameters, resultSetDataSource);
而且下面是報告中的圖像片段:
<image>
<reportElement x="0" y="1" width="555" height="61"/>
<imageExpression><![CDATA[$P{logo}]]>
</imageExpression>
</image>
先生,我也一樣,但它並沒有發生圖像不從classpath和PDF報告加載不產生 – Amit
圖像爵士沒有與加載此代碼並獲取錯誤「java.lang.IllegalArgumentException:input == null!」 – Amit
我假設你用'「header.png」'替換'「/images/IMAGE.png」'?如果它在jar的默認包中,請嘗試'「/header.png」'。 –