I am trying to generate a Jasper report from my Java code, my Java application is Swing. I designed the Jasper report using the TIBCO Jaspersoft Studio 6.0.0 final
. However, in my report, there is a Logo image. The image location is dynamically passed, it works fine when previewed on Jaspersoft Studio. Below is how the image is set in JasperSoft studio.The imagePath
variable is String
<image>
<reportElement x="210" y="0" width="140" height="76" uuid="2c20bfe9-e8af-4ca4-9c06-3c81ebe5f8a1"/>
<imageExpression><![CDATA[$P{imagePath}]]></imageExpression>
</image>
This is how I generate the report in Java.
private class PrintClientListBtnAction implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
ReportConnector r = new ReportHandler();
try {
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("imagePath", ClassLoader.getSystemResourceAsStream("/ReportResources/Logo_Big2i.png"));
r.printReport(getClass().getResourceAsStream("/ReportResources/Core_Clients.jasper"), params);
} catch (JRException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, ex.getLocalizedMessage(),"Printing error",JOptionPane.ERROR_MESSAGE);
}
}
}
The problem is, the report generated by the Java code do not have an image! what is wrong here?
Update
I tried with imagePath
as InputStream
as well, but the same result is here...
I don't think your images should be loaded through the system class loader. Try replacing
ClassLoader.getSystemResourceAsStream(
By
PrintClientListBtnAction.class.getResourceAsStream(
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.