gpt4 book ai didi

java - Jasper Report 中的动态图像大小

转载 作者:行者123 更新时间:2023-12-01 13:02:08 25 4
gpt4 key购买 nike

我正在尝试打印带有图像的 Jasper 报告。使用参数动态显示图像。图像打印良好。但我也需要动态输出图像大小。如何将图像尺寸(以英寸为单位)作为参数传递并获得预期的输出?

<image>
<reportElement uuid="a4ed8a3a-827e-494c-ba8d-7276007941c7" x="0" y="0" width="555" height="608"/>
<imageExpression><![CDATA[$P{IMAGE_LOCATION}]]></imageExpression>
</image>

最佳答案

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;
}

您可以动态设置宽度和高度。

关于java - Jasper Report 中的动态图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23446640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com