Search code examples
imagejasper-reportsheightshift

Cover blank space of image by other elements of Jasper Report


I have an image height of 360px and width of 900px. According to my condition sometimes image will be blank so it does not show in the PDF or EXCEL.

At this point, when image is not their than other element positioned according to their set "y" axis. Because of this a gap is formed.

So how to set their all the other elements position to top when image is not their.

<image isUsingCache="true" onErrorType="Icon">
                <reportElement x="448" y="0" width="402" height="300" uuid="d8d19734-1711-461d-bdb8-c8c7130a6eb2">
                    <printWhenExpression><![CDATA[($P{chartImg2}!=null ? true : false)]]></printWhenExpression>
                </reportElement>
                <imageExpression><![CDATA[$P{chartImg2}]]></imageExpression>
            </image>
            <textField>
                <reportElement style="REPORT_TITLE" mode="Opaque" x="0" y="320" width="850" height="30" uuid="aabbe2ed-96eb-4246-8bda-16187228c116">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.y" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                </reportElement>
                <textElement textAlignment="Center">
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{campaign_name}+"- Links Report"]]></textFieldExpression>
            </textField>

So, now you can see that image is of 300 height than textfield is positioned at 320px so image is not their than still textfield will be shown after 320px. Its looks bad in PDF. So I want if image is not their than all the element shift above.


Solution

  • I got the solution of my problem. You need to add elements into frame which are depends upon the condition. Here in above question like image may or may not be there.

    So In this case add this image into frame and changed other elements are positioned to float. (There is a property available in all the elements positionedType="float")

    Bingo!!! Problem is solved.