Jump to content
We've recently updated our Privacy Statement, available here ×

How to create pdf with subreport containing other subreport


jaswanth.pasupuleti

Recommended Posts

Hi,

I had a requriement where main report has a subreport and that subreport will have subreport when i tried but first subreport is printing and second subreport is not printing. below the code for referenece

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

Main Report

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.14.0.final using JasperReports Library version 6.14.0-2ab0d8625be255bf609c78e1181801213e51db8f  -->
<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="MAIN_REPORT" pageWidth="1210" pageHeight="1000" columnWidth="1210" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="856599dd-ebc6-4f22-9d21-3e4dc7618be8">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <parameter name="SUB_REPORT_1" class="net.sf.jasperreports.engine.JasperReport"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="pdfReports" class="java.util.Collection"/>
    <background>
        <band height="1000" splitType="Stretch">
            <line>
                <reportElement x="0" y="0" width="1209" height="1" uuid="a2c629c8-6560-4d97-9c88-48530e97c2ba"/>
            </line>
            <line>
                <reportElement x="0" y="1" width="1" height="999" uuid="1b750ab1-fcf1-4b58-b68e-da7393a0f8ae"/>
            </line>
            <line>
                <reportElement x="1209" y="1" width="1" height="999" uuid="e4a58f07-b367-49b9-bc44-738d0103be84"/>
            </line>
            <line>
                <reportElement x="1" y="999" width="1208" height="1" uuid="0d650c4d-4860-4c89-ae05-32639af624fe"/>
            </line>
            <frame>
                <reportElement mode="Opaque" x="1" y="1" width="1208" height="998" backcolor="#F2F3F6" uuid="f0024848-eb67-4299-9b09-18abc626c763"/>
            </frame>
        </band>
    </background>
    <detail>
        <band height="39" splitType="Stretch">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <frame>
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Opaque" x="1" y="0" width="1197" height="39" uuid="c1b85096-81f7-4684-9787-61ee1dd04609">
                    <property name="com.jaspersoft.studio.unit.width" value="px"/>
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
            </frame>
        </band>
        <band height="185">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <staticText>
                <reportElement mode="Opaque" x="9" y="20" width="1191" height="25" uuid="6a4e5c95-6ea8-4406-a7db-f29e76bbf5b3"/>
                <textElement verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
                <text><![CDATA[  Dashboard]]></text>
            </staticText>
            <line>
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="8" y="20" width="1" height="158" isPrintWhenDetailOverflows="true" uuid="78923086-338b-440e-b93d-0c7821256309">
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <graphicElement>
                    <pen lineColor="#9E9D9D"/>
                </graphicElement>
            </line>
            <line>
                <reportElement x="8" y="19" width="1192" height="1" uuid="62d44efe-313e-47e9-a000-089d0844b575"/>
                <graphicElement>
                    <pen lineColor="#9E9D9D"/>
                </graphicElement>
            </line>
            <line>
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="1200" y="20" width="1" height="158" isPrintWhenDetailOverflows="true" uuid="6e9cdb6f-2e9a-4452-adfc-344ed3a44663">
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <graphicElement>
                    <pen lineColor="#9E9D9D"/>
                </graphicElement>
            </line>
            <line>
                <reportElement positionType="Float" x="8" y="179" width="1192" height="1" uuid="715bdf58-71b0-47bc-8816-3516e69e3832"/>
                <graphicElement>
                    <pen lineColor="#9E9D9D"/>
                </graphicElement>
            </line>
            <frame>
                <reportElement stretchType="RelativeToTallestObject" x="9" y="50" width="1192" height="120" uuid="2bffe2b8-6566-4992-b221-3c6f95d47114"/>
                <subreport>
                    <reportElement x="10" y="5" width="1150" height="110" uuid="2a2e5ed5-b364-4611-af5f-4e49563dcaa7">
                        <property name="com.jaspersoft.studio.unit.y" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.x" value="px"/>
                    </reportElement>
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{pdfReports})]]></dataSourceExpression>
                    <subreportExpression><![CDATA[$P{SUB_REPORT_1}]]></subreportExpression>
                </subreport>
            </frame>
        </band>
    </detail>
    <pageFooter>
        <band height="25">
            <staticText>
                <reportElement x="0" y="0" width="1210" height="25" uuid="0a6215d4-25fd-452e-9069-f7aae7f8173a"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="12"/>
                </textElement>
    
            </staticText>
        </band>
    </pageFooter>
</jasperReport>

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

SUB_REPORT_1

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.14.0.final using JasperReports Library version 6.14.0-2ab0d8625be255bf609c78e1181801213e51db8f  -->
<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="GRAPH_TYPE_REPORT" pageWidth="1200" pageHeight="1000" columnWidth="1200" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="83e339c4-88d5-480a-a34b-4f9c330c5593">
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <parameter name="SUB_REPORT_2" class="net.sf.jasperreports.engine.JasperReport"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="reportType" class="java.lang.String"/>
    <field name="svgMarkup" class="java.lang.String"/>
    <field name="graphDropDownOptions" class="java.util.Map"/>
    <field name="graphType" class="java.lang.String"/>
    <field name="tableGraphData" class="java.util.Collection"/>
    <columnHeader>
        <band height="35" splitType="Stretch">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <line>
                <reportElement x="10" y="0" width="1161" height="1" uuid="a6d2adc7-2f9a-4d4b-ac15-40f9bc09bdd9"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement x="10" y="34" width="1161" height="1" uuid="1b13e538-ff7e-4287-8d38-57aec9699060">
                    <property name="com.jaspersoft.studio.unit.x" value="px"/>
                </reportElement>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement x="9" y="0" width="1" height="34" uuid="be301d0a-35b9-4466-8b00-f94c0f82196f">
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement x="1171" y="1" width="1" height="34" uuid="b313edbf-f8f6-4d12-8ae3-ad58f44a0395">
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <textField>
                <reportElement x="47" y="3" width="300" height="28" uuid="f747035f-83f3-44ef-9b57-1ffd11153e71">
                    <property name="com.jaspersoft.studio.unit.width" value="px"/>
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <textElement textAlignment="Justified" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{reportType}.toUpperCase()]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
    <detail>
        <band height="50">
            <line>
                <reportElement x="1171" y="0" width="1" height="50" uuid="8a60562c-bb11-4140-9705-15083653a098">
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement x="9" y="0" width="1" height="50" uuid="63724feb-41cd-45fd-954f-78947a75bf25">
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
        </band>
        <band height="450" splitType="Prevent">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <line>
                <reportElement stretchType="RelativeToTallestObject" x="9" y="0" width="1" height="449" uuid="4e03e955-3eda-4aa7-a9c7-5f216054d208">
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement stretchType="RelativeToTallestObject" x="1171" y="0" width="1" height="449" uuid="11c93787-4a11-4153-91ff-4ab357f2e38d">
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <image hAlign="Center" vAlign="Middle">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="30" y="10" width="1120" height="420" uuid="cbf6e11b-69d2-429b-99cd-52fe6a7e34cf"/>
                <imageExpression><![CDATA[net.sf.jasperreports.renderers.BatikRenderer.getInstanceFromText($F{svgMarkup})]]></imageExpression>
            </image>
        </band>
        <band height="150">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <line>
                <reportElement x="9" y="0" width="1" height="150" uuid="5d530b2c-dfbf-4ec6-bcf4-05c0ee2ccbe4">
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement x="1171" y="0" width="1" height="150" uuid="b2447fee-f364-4c6e-ae1e-05a12bdd3003">
                    <property name="com.jaspersoft.studio.unit.height" value="px"/>
                </reportElement>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <subreport>
                <reportElement x="30" y="5" width="1120" height="140" uuid="4061023f-32e2-4324-a1e1-7d61d6ac4aab"/>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{tableGraphData})]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{SUB_REPORT_2}]]></subreportExpression>
            </subreport>
        </band>
        <band height="1">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <line>
                <reportElement x="11" y="0" width="1161" height="1" uuid="075e4f71-7489-4fae-ad0d-9b05b08c9334"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
        </band>
    </detail>
</jasperReport>

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

SUB_REPORT_2

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.14.0.final using JasperReports Library version 6.14.0-2ab0d8625be255bf609c78e1181801213e51db8f  -->
<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="SUB_REPORT_2" pageWidth="1200" pageHeight="1000" columnWidth="1200" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="83e339c4-88d5-480a-a34b-4f9c330c5593">
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="dName" class="java.lang.String"/>
    <field name="pIndex" class="java.lang.String"/>
    <field name="ownedby" class="java.lang.String"/>
    <columnHeader>
        <band height="27" splitType="Stretch">
            <staticText>
                <reportElement mode="Opaque" x="20" y="1" width="383" height="25" backcolor="#EBEBEB" uuid="32daa97d-3afc-4359-9f28-49e9274699f9">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="37f35548-edac-4a6f-81f9-a6e877f2d87d"/>
                </reportElement>
                <textElement verticalAlignment="Middle">
                    <font fontName="SansSerif" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[ Name]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="414" y="1" width="371" height="25" backcolor="#EBEBEB" uuid="5826a90e-def4-44b4-b0b8-4e766c286699">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="01270d0c-73c2-447e-8871-2062648255a6"/>
                </reportElement>
                <textElement verticalAlignment="Middle">
                    <font fontName="SansSerif" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[P Index %]]></text>
            </staticText>
            <staticText>
                <reportElement mode="Opaque" x="796" y="1" width="375" height="25" backcolor="#EBEBEB" uuid="9d7f792e-3e7d-428f-b586-b2fdd13af4da">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4ffa44ca-7286-47f2-b93e-02f1ae77242c"/>
                </reportElement>
                <textElement verticalAlignment="Middle">
                    <font fontName="SansSerif" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Owned By]]></text>
            </staticText>
            <frame>
                <reportElement mode="Opaque" x="10" y="1" width="10" height="25" backcolor="#EBEBEB" uuid="1eb5eaf5-2afb-4057-a4c7-8dca6981df48"/>
            </frame>
            <frame>
                <reportElement mode="Opaque" x="404" y="1" width="10" height="25" backcolor="#EBEBEB" uuid="e3909591-1952-4e15-99e5-e98c2e1a0e25"/>
            </frame>
            <frame>
                <reportElement mode="Opaque" x="786" y="1" width="10" height="25" backcolor="#EBEBEB" uuid="d5986c46-60a5-4b33-91b0-e40091ea39cb"/>
            </frame>
            <line>
                <reportElement x="10" y="0" width="1161" height="1" uuid="a6d2adc7-2f9a-4d4b-ac15-40f9bc09bdd9"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement x="10" y="26" width="1161" height="1" uuid="1b13e538-ff7e-4287-8d38-57aec9699060"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement x="9" y="0" width="1" height="25" uuid="be301d0a-35b9-4466-8b00-f94c0f82196f"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement x="403" y="1" width="1" height="25" uuid="c595471b-62e2-4771-b66e-202b622f64a4"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement x="785" y="1" width="1" height="25" uuid="ba40331b-9db5-4881-80b0-c93cffbec761"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement x="1171" y="1" width="1" height="25" uuid="b313edbf-f8f6-4d12-8ae3-ad58f44a0395"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
        </band>
    </columnHeader>
    <detail>
        <band height="26" splitType="Prevent">
            <textField textAdjust="StretchHeight" isBlankWhenNull="true">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Opaque" x="20" y="0" width="383" height="25" isRemoveLineWhenBlank="true" forecolor="#000000" uuid="44df17df-2980-4516-a4ff-582b10256bb4">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="37f35548-edac-4a6f-81f9-a6e877f2d87d"/>
                </reportElement>
                <textElement verticalAlignment="Middle">
                    <font fontName="SansSerif" size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{dName}]]></textFieldExpression>
            </textField>
            <textField textAdjust="StretchHeight" isBlankWhenNull="true">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Opaque" x="414" y="0" width="371" height="25" isRemoveLineWhenBlank="true" uuid="a4139d18-4211-4a29-bad8-8bcb298590e9">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="01270d0c-73c2-447e-8871-2062648255a6"/>
                </reportElement>
                <textElement verticalAlignment="Middle">
                    <font fontName="SansSerif" size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{pIndex}]]></textFieldExpression>
            </textField>
            <textField textAdjust="StretchHeight" isBlankWhenNull="true">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Opaque" x="796" y="0" width="375" height="25" isRemoveLineWhenBlank="true" uuid="74e623e6-0c23-44e3-b608-d6c41d6ba7c3">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4ffa44ca-7286-47f2-b93e-02f1ae77242c"/>
                </reportElement>
                <textElement verticalAlignment="Middle">
                    <font fontName="SansSerif" size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{ownedby}]]></textFieldExpression>
            </textField>
            <frame>
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Opaque" x="10" y="0" width="10" height="25" uuid="648aefab-aab6-450c-bed7-5416901e93e2"/>
            </frame>
            <frame>
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Opaque" x="786" y="0" width="10" height="25" uuid="14ae0845-b0a7-44c3-b3d3-b7bd4af9fdf3"/>
            </frame>
            <staticText>
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Opaque" x="404" y="0" width="10" height="25" uuid="8c1b153a-9da6-4181-8a3e-0a5b0506fc23"/>
                <text><![CDATA[]]></text>
            </staticText>
            <line>
                <reportElement stretchType="RelativeToTallestObject" x="9" y="0" width="1" height="25" uuid="4e03e955-3eda-4aa7-a9c7-5f216054d208"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement stretchType="RelativeToTallestObject" x="403" y="0" width="1" height="25" uuid="844b3d09-d22b-492a-930f-6911c955f31a"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement stretchType="RelativeToTallestObject" x="785" y="0" width="1" height="25" uuid="9aa8a823-2872-4b77-8380-f356481b4fec"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
            <line>
                <reportElement stretchType="RelativeToTallestObject" x="1171" y="0" width="1" height="25" uuid="11c93787-4a11-4153-91ff-4ab357f2e38d"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
        </band>
        <band height="1">
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <line>
                <reportElement x="11" y="0" width="1161" height="1" uuid="075e4f71-7489-4fae-ad0d-9b05b08c9334"/>
                <graphicElement>
                    <pen lineWidth="1.0" lineStyle="Solid" lineColor="#ABA9A9"/>
                </graphicElement>
            </line>
        </band>
    </detail>
</jasperReport>

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

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...