subreport overflows the page width when used in main report

If I preview the subreport individualy, it respects the width  page size, but when it is embbeded in a main report, it overflows the page , as you can see 

--------------------- main report -----------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.19.0.final using JasperReports Library version 6.19.0-646c68931cebf1a58bc65c4359d1f0ca223c5e94  -->
<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="mainreport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="15617b9c-2c80-4382-8940-3ef863d8dc21">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="sampledata"/>
    <queryString language="JSON">
        <![CDATA[sampledata]]>
    </queryString>
    <field name="text1" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="text1"/>
        <fieldDescription><![CDATA[text1]]></fieldDescription>
    </field>
    <field name="subreport" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="subreport"/>
        <fieldDescription><![CDATA[subreport]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement x="210" y="20" width="100" height="30" uuid="c0776897-ce67-4b63-8614-7ef5a5195920"/>
                <text><![CDATA[Main report]]></text>
            </staticText>
        </band>
    </title>
    <detail>
        <band height="275" splitType="Stretch">
            <subreport>
                <reportElement x="0" y="10" width="460" height="200" uuid="66d1d2f2-43e7-483b-bfde-496605594a12"/>
                <subreportParameter name="REPORT_DATA_SOURCE">
                    <subreportParameterExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("subreport")]]></subreportParameterExpression>
                </subreportParameter>
                <subreportExpression><![CDATA["subreport.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>
 

-----

--------- sub report   -------------

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.19.0.final using JasperReports Library version 6.19.0-646c68931cebf1a58bc65c4359d1f0ca223c5e94  -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1d8a8cbf-ade7-44a8-8225-bdfd49f5f2f2">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="sampledata"/>
    <queryString language="JSON">
        <![CDATA[sampledata.subreport]]>
    </queryString>
    <field name="textsupreport" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="textsupreport"/>
        <fieldDescription><![CDATA[textsupreport]]></fieldDescription>
    </field>
    <detail>
        <band height="125" splitType="Stretch">
            <staticText>
                <reportElement mode="Opaque" x="0" y="2" width="555" height="18" forecolor="#FFFFFF" backcolor="#787777" uuid="7e5e2de5-05c9-4c38-8c32-9fc8a8d3be85"/>
                <text><![CDATA[Subreport]]></text>
            </staticText>
            <textField>
                <reportElement x="121" y="63" width="100" height="30" uuid="93605355-8fa4-477f-b41f-96dfc836ae4d"/>
                <textFieldExpression><![CDATA[$F{textsupreport}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="21" y="63" width="100" height="30" uuid="e7cb2bc1-a62c-4947-983b-ee022132042b"/>
                <text><![CDATA[text1]]></text>
            </staticText>
        </band>
    </detail>
</jasperReport>

 

 

---------------------

 

 

 

 

lorenzo.brito's picture
Joined: Mar 6 2022 - 10:27am
Last seen: 1 year 2 months ago

2 Answers:

Don't use margings in the SubReport when used within a MainReport... that's it what I would first try

As the margins are fixed

regards from Germany

C-Box

C-Box's picture
20743
Joined: Jul 19 2006 - 5:58pm
Last seen: 5 months 2 weeks ago

As C-Box says, we dont have to use margins in the subreport. 

 

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.19.0.final using JasperReports Library version 6.19.0-646c68931cebf1a58bc65c4359d1f0ca223c5e94  -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="20" bottomMargin="20" uuid="1d8a8cbf-ade7-44a8-8225-bdfd49f5f2f2">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="sampledata"/>
    <queryString language="JSON">
        <![CDATA[sampledata.subreport]]>
    </queryString>
    <field name="textsupreport" class="java.lang.String">
        <property name="net.sf.jasperreports.json.field.expression" value="textsupreport"/>
        <fieldDescription><![CDATA[textsupreport]]></fieldDescription>
    </field>
    <detail>
        <band height="125" splitType="Stretch">
            <staticText>
                <reportElement mode="Opaque" x="0" y="2" width="595" height="18" forecolor="#FFFFFF" backcolor="#787777" uuid="7e5e2de5-05c9-4c38-8c32-9fc8a8d3be85"/>
                <text><![CDATA[Subreport 2.0]]></text>
            </staticText>
            <textField>
                <reportElement x="121" y="63" width="100" height="30" uuid="93605355-8fa4-477f-b41f-96dfc836ae4d"/>
                <textFieldExpression><![CDATA[$F{textsupreport}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="21" y="63" width="100" height="30" uuid="e7cb2bc1-a62c-4947-983b-ee022132042b"/>
                <text><![CDATA[text1]]></text>
            </staticText>
        </band>
    </detail>
</jasperReport>
 

lorenzo.brito's picture
Joined: Mar 6 2022 - 10:27am
Last seen: 1 year 2 months ago
Feedback
randomness