Reputation: 21
My java application is generating an image(basically an org chart) for a jasper report. As org charts go, there's no way one can determine the final size of the image output. Also the image output can grow too large, that cropping the image is useless.
Is it even possible to have the jasper report to dynamically resize it's image element without splitting the images?
Upvotes: 2
Views: 5727
Reputation: 14656
I've not tested this myself, but it it supposed to work. Get the image element from the design, change it's size, then compile the altered design.
BufferedImage img = ImageIO.read(new File(wo_image_path));
height = img.getHeight();
width = img.getWidth();
jasperSubDesign = JasperManager.loadXmlDesign(context.getRealPath("/WEB-INF/reports/decoration_sheet_header.jrxml"));
JRDesignImage image = (JRDesignImage)jasperSubDesign.getPageHeader().getElementByKey("wo_image");
image.setX(3);
image.setY(69);
image.setHeight(new Long(height - Math.round(height*.35)).intValue());
image.setWidth(new Long(width - Math.round(width*.35)).intValue());
JasperCompileManager.compileReportToFile(jasperSubDesign, context.getRealPath("/WEB-INF/reports/decoration_sheet_header.jasper"));
From Jasperforge
Upvotes: 0
Reputation: 64632
Try this:
<image scaleImage="ReatinShape" hAlign="Center">
<reportElement x="100" y="150" width="600" height="150"/>
<graphicElement/>
<imageExpression class="net.sf.jasperreports.engine.JRRenderable">
<![CDATA[new com.onbarcode.barcode.jasper.JasperRenderer(yourImage)]]></imageExpression>
</image>
Upvotes: 1