开发者

How do I add multiple pictures from database to a report "detail"?

开发者 https://www.devze.com 2023-04-06 07:07 出处:网络
I\'m building a report in iReport so I can generate PDFs from开发者_如何转开发 my db data. Along with my \"description\" field I have multiple images which I\'d like to display in the detail band. The

I'm building a report in iReport so I can generate PDFs from开发者_如何转开发 my db data. Along with my "description" field I have multiple images which I'd like to display in the detail band. The amount of pictures depends on the exact report I'm generating the PDF for. What is the best approach for display these images? I'd like them displayed one under the other with their appropriate captions. The filename/locations are store in a "pictures" table along with the captions. I assume I need a subreport?


You can use imageExpression property to managing WHAT picture to display. For example:

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

With help of printWhenExpression property you can manage WHEN you need to show image. For example:

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

The filename/locations are store in a "pictures" table along with the captions. I assume I need a subreport?

Yes, you cannot use several queries (datasources) in one report. And yes, you need a subreport.
You can return data from subreport to master data. You can view sample report at $IREPORT_HOME$\ireport\samples\Subreports folder and read this case.

UPDATED:
I've just found useful as I think article Creating jasper reports with dynamic images. May be it helps you.

0

精彩评论

暂无评论...
验证码 换一张
取 消