Search code examples
javajasper-reportsdynamic-reports

Render Image to XLS Report Using DynamicReports API


I want to render image from a folder and display in Excel report.

Following codes used to render.

String headerImagePath = "/file/fileName.jpg"
BufferedImage img = null;

try {
    img = ImageIO.read(new File(headerImagePath)); 

}  catch (IOException e)  {
    e.printStackTrace();
}
JasperReportBuilder report = report();
report.title(cmp.image(img));

But image is not showing in excel sheet.

Any other option to render an image?


Solution

  • Finally got it.!

    You need pass the image file name as a parameter.

         parameters.put("header", headerImagePath);
    

    Add the above parameters & it's Class to Jasper Report.

         report.addParameter("header", String.class);
    

    You can add the image to report as follows

         report.title(cmp.image(exp.jasperSyntax("($P{header})",String.class)).setDimension(50, 130));