如何将数据库中的多个图片添加到报告“详细信息”?

时间:2011-09-21 18:16:21

标签: mysql image ireport

我正在iReport中构建报告,因此我可以从我的数据库数据生成PDF。随着我的“描述”字段,我有多个图像,我想在细节带中显示。图片数量取决于我为其生成PDF的确切报告。显示这些图像的最佳方法是什么?我希望他们用适当的标题显示一个在另一个之下。文件名/位置与字幕一起存储在“图片”表中。我想我需要一个子报告?

1 个答案:

答案 0 :(得分:0)

您可以使用 imageExpression 属性来管理要显示的 WHAT 图片。例如:

        <parameter name="whatImageToShow" class="java.lang.Integer" isForPrompting="true">
            <defaultValueExpression><![CDATA[Integer.valueOf(1)]]></defaultValueExpression>
        </parameter>
        ...
        <image>
            <reportElement x="0" y="296" width="270" height="65"/>
            <imageExpression><![CDATA[$P{whatImageToShow}.intValue() == 0 ? "image1.jpg" : "image2.png"]]></imageExpression>
        </image>

借助 printWhenExpression 属性,您可以管理需要显示图片的 WHEN 。例如:

        <parameter name="toShowPicture" class="java.lang.Boolean" isForPrompting="true">
            <defaultValueExpression><![CDATA[CDATA[Boolean.valueOf(false)]]></defaultValueExpression>
        </parameter>
        ...
        <image>
            <reportElement x="0" y="296" width="270" height="65">
                <printWhenExpression><![CDATA[$P{toShowPicture}.booleanValue()]]></printWhenExpression>
            </reportElement>
            <imageExpression><![CDATA[$P{whatImageToShow}.intValue() == 0 ? "image3.jpg" : "image4.png"]]></imageExpression>
        </image>
  

文件名/位置与“图片”表一起存储在   字幕。我想我需要一个子报告?

是的,您不能在一个报告中使用多个查询(数据源)。是的,你需要一个子报告 您可以将数据从子报表返回到主数据。您可以在$ IREPORT_HOME $ \ ireport \ samples \ Subreports文件夹中查看示例报告,并阅读此case

<强>更新:
我觉得有用的文章Creating jasper reports with dynamic images。可能对你有帮助。

相关问题