0

I'm using iReport 4.5.1 (unfortunately using a later version is not an option) and have a report that has multiple sub-reports associated. In the Background band of the main report, I have placed text to be used as a watermark - this displays fine on each report page. In one sub-report I want to display an additional watermark, so have added an additional text field element in the background band of this report.

When I run the report as a whole, the watermark text for the sub-report does not display, yet when I run the sub-report separately, its watermark text displays fine. Any ideas why this might be happening?

4

2 回答 2

0

您可以查看此示例。

报告设计(在iReport中):

在此处输入图像描述

我在背景带上放置了 4 个静态文本。

主报告jrxml文件是:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="mainrep_watermark" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ffeb1237-be4e-4cca-8a63-223aa5d8f3e6">
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["/somepath"]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[SELECT * FROM product ORDER BY id]]>
    </queryString>
    <field name="ID" class="java.lang.Integer"/>
    <field name="NAME" class="java.lang.String"/>
    <field name="COST" class="java.math.BigDecimal"/>
    <group name="idgroup">
        <groupExpression><![CDATA[$F{ID}]]></groupExpression>
        <groupFooter>
            <band height="28">
                <subreport>
                    <reportElement uuid="710fe82b-fd08-4db3-bba1-929870f83fa4" x="100" y="0" width="200" height="27"/>
                    <subreportParameter name="productId">
                        <subreportParameterExpression><![CDATA[$F{ID}]]></subreportParameterExpression>
                    </subreportParameter>
                    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "subreport_watermark.jasper"]]></subreportExpression>
                </subreport>
            </band>
        </groupFooter>
    </group>
    <background>
        <band height="802" splitType="Stretch">
            <staticText>
                <reportElement uuid="0e7c3a54-8876-4523-9bad-2b582b1defb9" x="51" y="15" width="468" height="148" forecolor="#0033FF"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                    <font size="48"/>
                </textElement>
                <text><![CDATA[Master watermark 1]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="584b9b65-c040-43a0-96ce-6fa14e9db597" x="51" y="174" width="468" height="148" forecolor="#0033FF"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                    <font size="48"/>
                </textElement>
                <text><![CDATA[Master watermark 2]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="4f4f55b5-cbd4-4b10-bcf4-1e81d16bb537" x="51" y="344" width="468" height="148" forecolor="#0033FF"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                    <font size="48"/>
                </textElement>
                <text><![CDATA[Master watermark 3]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="10b1534f-d880-4ca3-9a2f-847d68826011" x="51" y="524" width="468" height="148" forecolor="#0033FF"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                    <font size="48"/>
                </textElement>
                <text><![CDATA[Master watermark 4]]></text>
            </staticText>
        </band>
    </background>
    <columnHeader>
        <band height="20" splitType="Stretch">
            <staticText>
                <reportElement uuid="d337add8-2a0d-4a9e-ad3c-3dfb322b715a" mode="Opaque" x="0" y="0" width="100" height="20" backcolor="#CCCCCC"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[Id]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="97ff3089-7082-4f30-850e-e59836ff48a2" mode="Opaque" x="100" y="0" width="100" height="20" backcolor="#CCCCCC"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[Name]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="ec4bc628-f6bb-40be-9e46-fd49327071f2" mode="Opaque" x="200" y="0" width="100" height="20" backcolor="#CCCCCC"/>
                <box>
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true" isItalic="true"/>
                </textElement>
                <text><![CDATA[Cost]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement uuid="2b43cdac-3453-499e-a6e0-b33eef8bf3f9" x="0" y="0" width="100" height="20"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="75ba99d4-646e-470c-b68b-fa111b702ac7" x="100" y="0" width="100" height="20"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="451db60d-5255-41fe-b5fe-8e523118fab3" x="200" y="0" width="100" height="20"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$F{COST}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

报表的设计是(在iReport中):

在此处输入图像描述

我在背景带上放置了一个staticText并将文本旋转 90 度。

子报表jrxml文件为:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="subreport_watermark" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="cf5d8eca-6c3a-4e1f-a6c9-107436e0ac48">
    <parameter name="productId" class="java.lang.String"/>
    <queryString language="SQL">
        <![CDATA[SELECT TOP 10 QUANTITY, PRICE FROM positions WHERE productid=$P{productId}]]>
    </queryString>
    <field name="QUANTITY" class="java.lang.Integer"/>
    <field name="PRICE" class="java.math.BigDecimal"/>
    <background>
        <band height="95" splitType="Stretch">
            <staticText>
                <reportElement uuid="f09a53bb-3b62-4e97-8e6b-2c592f469c3d" positionType="Float" stretchType="RelativeToBandHeight" x="78" y="0" width="100" height="95" forecolor="#FF3333"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" rotation="Left">
                    <font size="20"/>
                </textElement>
                <text><![CDATA[Subreport watermark]]></text>
            </staticText>
        </band>
    </background>
    <detail>
        <band height="15" splitType="Stretch">
            <textField>
                <reportElement uuid="135d5748-db78-4272-a1c8-a94f5ce5549e" x="43" y="0" width="60" height="15"/>
                <box leftPadding="10">
                    <topPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                    <leftPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                    <bottomPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                    <rightPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                </box>
                <textElement>
                    <font size="8"/>
                </textElement>
                <textFieldExpression><![CDATA["Quantity: " + $F{QUANTITY}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="8736b7b8-b7cd-4fd5-8494-9519cb55317c" x="103" y="0" width="60" height="15"/>
                <box leftPadding="10">
                    <topPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                    <leftPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                    <bottomPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                    <rightPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                </box>
                <textElement>
                    <font size="8"/>
                </textElement>
                <textFieldExpression><![CDATA["Price: " + $F{PRICE}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

结果将是(在Adob​​e Reader中生成的pdf):

在此处输入图像描述

于 2013-09-12T19:49:35.997 回答
0

谢谢 Alex K。我发现我的问题实际上是由于在我的主报告中定义了页眉。由于某种原因,这似乎覆盖了子报告显示的背景带。我不知道为什么,并且很想知道是否有人知道原因。我可以通过从主报告中删除页眉来解决我的问题。(user2756852/Deb)

于 2013-10-01T01:34:26.250 回答