我正在尝试用图像打印Jasper报告。使用参数动态显示图像。图像打印正常。但我也需要动态输出图像大小。如何将图像大小(以英寸为单位)作为参数传递并获得预期的输出?
<image>
<reportElement uuid="a4ed8a3a-827e-494c-ba8d-7276007941c7" x="0" y="0" width="555" height="608"/>
<imageExpression><![CDATA[$P{IMAGE_LOCATION}]]></imageExpression>
</image>
答案 0 :(得分:1)
public JasperDesign dynamicImage() throws JRException {
JasperDesign jasperDesign = new JasperDesign();
jasperDesign.setName("NoXmlDesignReport");
jasperDesign.setPageWidth(595);
jasperDesign.setPageHeight(842);
jasperDesign.setColumnWidth(515);
jasperDesign.setColumnSpacing(0);
jasperDesign.setLeftMargin(40);
jasperDesign.setRightMargin(40);
jasperDesign.setTopMargin(20);
jasperDesign.setBottomMargin(20);
JRDesignExpression expression = new JRDesignExpression();
//Summary
band = new JRDesignBand();
band.setHeight(125);
JRDesignImage jrDesignImage = new JRDesignImage(jasperDesign);
expression = new JRDesignExpression();
expression.setText("\"" "/path/to/image\"");
jrDesignImage.setExpression(expression);
jrDesignImage.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
jrDesignImage.setX(400);
jrDesignImage.setY(0);
jrDesignImage.setWidth(93);
jrDesignImage.setHeight(100);
jrDesignImage.setScaleImage(ScaleImageEnum.RETAIN_SHAPE);
band.addElement(jrDesignImage);
jasperDesign.setSummary(band);
return jasperDesign;
}
您可以动态设置宽度和高度。