How to reduce the blank space in report? - jasper-reports

This is my template:
<?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="report_viwe_2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="3cb87247-a775-45d7-b09b-4211897bff60">
<queryString language="SQL">
<![CDATA[SELECT * FROM team]]>
</queryString>
<field name="team_teamno" class="java.lang.String"/>
<field name="team_teamlead" class="java.lang.String"/>
<field name="team_teammem1" class="java.lang.String"/>
<field name="team_teammem2" class="java.lang.String"/>
<group name="team_teamlead">
<groupExpression><![CDATA[$F{team_teamlead}]]></groupExpression>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement uuid="bff92bff-1492-496c-b0e5-5e5e38f341e5" x="24" y="33" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{team_teamno}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="fa26359e-2fc7-4fdf-a972-9265832c77ac" x="162" y="33" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{team_teamlead}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="c425bb55-97cb-4949-8926-3159f109aaa8" x="284" y="33" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{team_teammem1}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="9dda41b1-e0f1-403d-ae59-ee7fe15889a3" x="414" y="33" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{team_teammem2}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="d6efe743-2133-45da-82ba-f8eb56e82c9e" x="39" y="4" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{team_teamno}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="d1b79bae-55ae-47e3-9b16-403af876b6d0" x="185" y="9" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{team_teamlead}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="a653ec3b-4ce4-4871-b784-a7fa9878293a" x="297" y="4" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{team_teammem1}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="c4bb9aa3-3dc2-4db0-a13b-31d43b1972d3" x="447" y="12" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{team_teammem2}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
I am just trying to print the JasperReports' report on web page using php.
The problem is while printing on web page, the first page will be blank, in next page it will display the data. I was reducing the band height. but yet there is a extra page appear.

Get rid of your empty bands. You have title, pageHeader and columnHeader bands that have declared heights but are unused. These bands will appear before your detail band. Delete them completely or at least set their heights to zero.
You also have background, columnFooter, pageFooter and summary bands that are empty and could be deleted too.

Related

SubReport not shown

I'd like to create a simple Jasper Report, with subreport, but I cannot make it work.
For example, I have two, simple report.
test1.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-01-18T23:29:14 -->
<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="test1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="553ce57f-5ea7-48e5-8eaa-dcfecf31880a">
<queryString>
<![CDATA[select dummy from dual]]>
</queryString>
<field name="dummy" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="89" y="0" width="100" height="30" uuid="04f9b63d-265b-45f0-a249-41464df6b4c0"/>
<text><![CDATA[x]]></text>
</staticText>
<staticText>
<reportElement x="227" y="0" width="100" height="30" uuid="0c7db454-653c-4dcf-af94-a0f1c9962b91"/>
<text><![CDATA[x]]></text>
</staticText>
<staticText>
<reportElement x="352" y="0" width="100" height="30" uuid="7ad861d5-74ba-49e9-95c7-4cd01d184dbe"/>
<text><![CDATA[x]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="257" splitType="Stretch">
<textField>
<reportElement x="89" y="66" width="100" height="30" uuid="4099071d-8bfc-4e61-a697-af078ccb626a"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="227" y="68" width="100" height="30" uuid="a955ca4e-aecd-48c3-8b7c-face6295b879"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="352" y="65" width="100" height="30" uuid="5a998443-ae4f-457d-a565-67b4f3405951"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="555" y="57" width="200" height="200" uuid="d6eada20-a566-4ba5-ab51-9d6ea0b4dfd9"/>
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<subreportParameter name="a">
<subreportParameterExpression><![CDATA[12]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA["test4.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
test4.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-01-18T23:27:56 -->
<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="test4" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c55e71d8-6eb9-4f20-9263-c50c295fa0d1">
<parameter name="a" class="java.lang.String"/>
<queryString>
<![CDATA[select dummy from dual where 1=1]]>
</queryString>
<field name="dummy" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="364" y="0" width="100" height="30" uuid="1d48df0f-3f4c-489f-b479-e981b2727590"/>
<text><![CDATA[b]]></text>
</staticText>
<staticText>
<reportElement x="478" y="0" width="100" height="30" uuid="397b1c60-fe4d-4f41-a7a4-7c585a57ac15"/>
<text><![CDATA[a]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<staticText>
<reportElement x="239" y="58" width="100" height="30" uuid="5b5c86c0-1b1b-44d3-87cb-2ad2782a3408"/>
<text><![CDATA[test4]]></text>
</staticText>
<textField>
<reportElement x="364" y="66" width="100" height="30" uuid="d3217648-88a1-4d88-b2b0-7f7cc4e598c6"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="478" y="47" width="100" height="30" uuid="f2c6bfb9-ee73-4928-8ce4-0a83060d0801"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
The selects provide one result (the DB is Oracle), but the subreport isn't visible in the repport made from test1.jrxml. But a whole new, empty page is at the end of the report.
Can you show me what's wrong with this example? I'd tried a lot's of stuff (default value in the subreport, When No Data = All Sections, No Detail setting in the subReport's header, and a lot of stuff, I can't remember), but nothing helped.
In your example I can see two problems:
You need to pass absolute path to subreport (this is normally done by parameter, so that it can be controlled on runtime)
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\jdd\\projects\\StackTrace\\jasper\\"]]></defaultValueExpression>
</parameter>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "test4.jasper"]]></subreportExpression>
You need to pass the report connection to the subreport
<subreport>
<reportElement x="555" y="57" width="200" height="200" uuid="d6eada20-a566-4ba5-ab51-9d6ea0b4dfd9"/>
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<subreportParameter name="a">
<subreportParameterExpression><![CDATA[12]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "test4.jasper"]]></subreportExpression>
</subreport>

Gap between detail and column footer bands even after setting "Float Column Footer" to true

I am creating a jasper report showing some person names. I need to show the number of persons in the list at the bottom.
The problem I am facing is I am getting a small gap between persons list and the label "Total Candidates".
For the reference, please check below image:
In the beginning, column footer was getting shown at the end of page, leaving a lot of gap. Then I found few good StackOverflow links:
1) Issue with Column footer and Summary bands
2) Jasper Reports - how to get column footer to appear directly below details band
which suggested to set "Float Column Footer" to true. After doing that, the gap reduced and my column footer is almost below the detail band. But still, as shown in the picture, there is some gap remaining, which I don't know how to remove.
Edit: Here is my jrxml file:
<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true" uuid="b7718df8-d1d7-46e7-9a66-7d3fe24c720c">
<parameter name="ReportName" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="firstName" class="java.lang.String">
<fieldDescription><![CDATA[firstName]]></fieldDescription>
</field>
<field name="id" class="java.lang.String">
<fieldDescription><![CDATA[id]]></fieldDescription>
</field>
<field name="lastName" class="java.lang.String">
<fieldDescription><![CDATA[lastName]]></fieldDescription>
</field>
<field name="middleName" class="java.lang.String">
<fieldDescription><![CDATA[middleName]]></fieldDescription>
</field>
<title>
<band height="42" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="555" height="42" uuid="b6eaae95-75f5-4b33-978b-8afd7f9ecfee"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="20"/>
</textElement>
<textFieldExpression><![CDATA[$P{ReportName}]]></textFieldExpression>
</textField>
</band>
</title>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="32" height="20" uuid="3dfe1b88-b77c-465e-bc1d-d96223c69692"/>
<text><![CDATA[Sr. No.]]></text>
</staticText>
<staticText>
<reportElement x="32" y="0" width="188" height="20" uuid="96add808-7f90-405d-93fc-ae64596df9e3"/>
<textElement textAlignment="Center"/>
<text><![CDATA[First Name]]></text>
</staticText>
<staticText>
<reportElement x="220" y="0" width="188" height="20" uuid="dd5aa422-a23c-4a4c-a464-9e927503c342"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Middle Name]]></text>
</staticText>
<staticText>
<reportElement x="408" y="0" width="147" height="20" uuid="e7894574-4f95-4a04-b54b-16f636dc453c"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Last Name]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="32" height="20" uuid="b0a9a50f-f275-4802-ba80-04559e57c75e"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="32" y="0" width="188" height="20" uuid="4ea4f73b-06bb-4553-848b-eecdc6be51b2"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="220" y="0" width="188" height="20" uuid="d2ea4610-7ee7-4921-babe-6d9040592843"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{middleName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="408" y="0" width="147" height="20" uuid="045272ac-1387-49c6-a4e1-237725e08269"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{lastName}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="79" height="20" uuid="5a71d074-89c3-4b70-ae90-840cb37b45e8"/>
<text><![CDATA[Total Candidates:]]></text>
</staticText>
</band>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Any suggestions would be really appreciated!
<summary>
<band height="0" splitType="Stretch"/>
</summary>
or remove the tag completely.

Subreport using XML file datasource don't work

I'm having a problem with subreport connected to a XML file. When I execute the report the preview don't show the subreport data, but if I execute the subreport alone, it shows the data correctly. What am I doing wrong?
Data File:
<REPORTDATA>
<HEAD>
<NUMBER>1</NUMBER>
<DESC>BLA BLA</DESC>
<DATE>2012.01.01</DATE>
</HEAD>
<GRID1>
<line id="1">
<NUMBER>11</NUMBER>
<DESC>g11BLA BLA</DESC>
<DATE>2012.01.01</DATE>
</line>
<line id="2">
<NUMBER>12</NUMBER>
<DESC>g12BLA BLA</DESC>
<DATE>2012.01.01</DATE>
</line>
</GRID1>
<GRID2>
<line id="1">
<NUMBER>21</NUMBER>
<DESC>g21BLA BLA</DESC>
<DATE>2012.01.01</DATE>
</line>
<line id="2">
<NUMBER>22</NUMBER>
<DESC>g22BLA BLA</DESC>
<DATE>2012.01.01</DATE>
</line>
</GRID2>
Report:
<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="reporttest" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6a9eed56-d1c3-46d8-9e16-4166c146b8a3">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\Users\\A2O\\Desktop\\"]]></defaultValueExpression>
</parameter>
<queryString language="xPath">
<![CDATA[/REPORTDATA/HEAD]]>
</queryString>
<field name="NUMBER" class="java.lang.String">
<fieldDescription><![CDATA[NUMBER]]></fieldDescription>
</field>
<field name="DESC" class="java.lang.String">
<fieldDescription><![CDATA[DESC]]></fieldDescription>
</field>
<field name="DATE" class="java.lang.String">
<fieldDescription><![CDATA[DATE]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement uuid="bd7929b3-092d-44b9-b488-c0418fb57749" x="4" y="6" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="de902808-67e8-4b08-bd0b-c1d735409843" x="6" y="32" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{DESC}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="86d57bd0-01d3-4b1f-b9bb-0eb7cf2c19fc" x="5" y="56" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{DATE}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="13" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="12" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="26" splitType="Stretch">
<staticText>
<reportElement uuid="819f4027-8ad0-46b4-b07c-c80234fe8411" x="12" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[Static text]]></text>
</staticText>
</band>
</detail>
<columnFooter>
<band height="11" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="9" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch">
<subreport>
<reportElement uuid="4ab29d23-9ead-491e-8ca3-8f9790280026" x="0" y="0" width="555" height="42"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "reporttest_subreport1.jasper"]]></subreportExpression>
</subreport>
</band>
</summary>
Subreport:
<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="reporttest_subreport1" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="ca109af7-4e08-405d-b43f-4062115c500e">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="xPath">
<![CDATA[/REPORTDATA/GRID1/line]]>
</queryString>
<field name="NUMBER" class="java.lang.String">
<fieldDescription><![CDATA[NUMBER]]></fieldDescription>
</field>
<field name="DESC" class="java.lang.String">
<fieldDescription><![CDATA[DESC]]></fieldDescription>
</field>
<field name="DATE" class="java.lang.String">
<fieldDescription><![CDATA[DATE]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band height="36" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="69" splitType="Stretch">
<staticText>
<reportElement uuid="867a24dd-6172-40ef-be33-f8e51fa21207" x="0" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[Grid1 data:]]></text>
</staticText>
<staticText>
<reportElement uuid="0885dada-a149-4cb7-b82c-fdfa9847061d" x="32" y="49" width="100" height="20"/>
<textElement/>
<text><![CDATA[NUMBER]]></text>
</staticText>
<staticText>
<reportElement uuid="7261c001-6771-47dc-9749-5e6f64fb86df" x="159" y="49" width="100" height="20"/>
<textElement/>
<text><![CDATA[DESC]]></text>
</staticText>
<staticText>
<reportElement uuid="2b95c6fc-3fd9-4df1-89c6-5249173db3e1" x="287" y="49" width="100" height="20"/>
<textElement/>
<text><![CDATA[DATE]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="23" splitType="Stretch">
<textField>
<reportElement uuid="becea2ba-40fd-4208-8191-c7475293ed5b" x="32" y="1" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="182efb3b-6a66-4634-be35-fe03e8a0cd45" x="159" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{DESC}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="bdb70a35-b4e6-4857-96c5-f607ee59bc07" x="287" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{DATE}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="15" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="6" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="7" splitType="Stretch"/>
</summary>
For sub report with the xml files as a datasource, you need to specify the datasource for the sub report.
Properties you need to have a look at are
Connection Type : Use a Datasource Expression
Connection / Datasource Expression :
((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//YOUR_SUBREPORT_ENTITY").
You will need something similar to this
<dataSourceExpression><![CDATA[
((net.sf.jasperreports.engine.data.JRXmlDataSource)
$P{REPORT_DATA_SOURCE}).subDataSource("//YOUR_SUBREPORT_ENTITY") ]]>
</dataSourceExpression>
Maybe now its not actually for you, but someone it help.
All what need - its set datasource expression for subreport, how it realise:
<dataSourceExpression>
<![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).datasource("YOUR_SUBREPORT_XPATH") ]]>
</dataSourceExpression>
Instead "YOUR_SUBREPORT_XPATH" use XPath that you set in subreport. In this case it will be "/REPORTDATA/GRID1/line"
In newer versions of Jasper (i used 6.x) is better and correct use .datasource(...) instead .subDataSource(...)

Jasper Reports: How can I print multiple pages in one page

I am new to Jasper Reports. I have a report with 2 groups. Depending on the query, multiple pages are being printed.
1st Group Height -- 95 Points and 2nd Group Height -- 144 Points
I want these multiple pages to be printed in one page (I want to incorporate 5 pages in a page). Each page height is 239 Points. (Even if content of page is less than 239 Points, I want to keep the remaining part as blank and start the next page after 239 Points). I tried creating a Report and included the above report as a sub-report and set the height of main report as 1195 (239 * 5) Points. Still, these are being printed in different pages.
The result of export is:
The main report design is:
The first subreport design is:
The second subreport design is:
Please help me regarding this.
I've made a test based on your specifications and it seems to work just fine. I can give you a couple of pointers here.
In your main-report design, the height of the sub-report element doesn't matter as long as it is equal to the underlying band. If the sub-report element is shorter, the difference will appear in the result.
The page height of the sub-report doesn't matter, just the total height of the bands.
Check to make sure that the "Start on a new Page" option hasn't been selected on the groups that you have created. This is the most likely issue.
If the top 3 hasn't fixed your problem, look through the sample below and compare differences.
MainReport:
<?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="MainReport1" language="groovy" pageWidth="595" pageHeight="1195" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="0" bottomMargin="0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\Users\\Bizz\\Documents\\JasperReports\\"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT
PRODUCT."ID" AS PRODUCT_ID,
PRODUCT."NAME" AS PRODUCT_NAME,
PRODUCT."COST" AS PRODUCT_COST
FROM
"PUBLIC"."PRODUCT" PRODUCT]]>
</queryString>
<field name="PRODUCT_ID" class="java.lang.Integer"/>
<field name="PRODUCT_NAME" class="java.lang.String"/>
<field name="PRODUCT_COST" class="java.math.BigDecimal"/>
<group name="Group1">
<groupExpression><![CDATA[$F{PRODUCT_ID}]]></groupExpression>
<groupHeader>
<band height="50">
<subreport>
<reportElement x="0" y="0" width="200" height="50"/>
<subreportParameter name="ProductID">
<subreportParameterExpression><![CDATA[$F{PRODUCT_ID}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "MainReport1_subreport2.jasper"]]></subreportExpression>
</subreport>
</band>
</groupHeader>
</group>
<group name="Group2">
<groupExpression><![CDATA["2"]]></groupExpression>
<groupHeader>
<band height="50">
<subreport>
<reportElement x="0" y="0" width="200" height="50"/>
<subreportParameter name="ProductID">
<subreportParameterExpression><![CDATA[$F{PRODUCT_ID}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "MainReport1_subreport1.jasper"]]></subreportExpression>
</subreport>
</band>
</groupHeader>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band splitType="Stretch"/>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
Subreport1:
<?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="MainReport1_subreport1" language="groovy" pageWidth="555" pageHeight="95" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="ProductID" class="java.lang.Integer"/>
<queryString>
<![CDATA[SELECT
PRODUCT."ID" AS PRODUCT_ID,
PRODUCT."NAME" AS PRODUCT_NAME,
PRODUCT."COST" AS PRODUCT_COST
FROM
"PUBLIC"."PRODUCT" PRODUCT
where
product_id = $P{ProductID}]]>
</queryString>
<field name="PRODUCT_ID" class="java.lang.Integer"/>
<field name="PRODUCT_NAME" class="java.lang.String"/>
<field name="PRODUCT_COST" class="java.math.BigDecimal"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="95" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_ID]]></text>
</staticText>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_ID}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="20" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_NAME]]></text>
</staticText>
<textField>
<reportElement x="100" y="20" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_NAME}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="40" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_COST]]></text>
</staticText>
<textField>
<reportElement x="100" y="40" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_COST}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement x="0" y="60" width="200" height="35"/>
<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="3of9" drawText="false" checksumRequired="false">
<jr:codeExpression><![CDATA[$F{PRODUCT_ID}]]></jr:codeExpression>
</jr:barbecue>
</componentElement>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
Subreport2:
<?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="MainReport1_subreport2" language="groovy" pageWidth="555" pageHeight="888" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="ProductID" class="java.lang.Integer"/>
<queryString>
<![CDATA[SELECT
PRODUCT."ID" AS PRODUCT_ID,
PRODUCT."NAME" AS PRODUCT_NAME,
PRODUCT."COST" AS PRODUCT_COST
FROM
"PUBLIC"."PRODUCT" PRODUCT
where
product_id = $P{ProductID}]]>
</queryString>
<field name="PRODUCT_ID" class="java.lang.Integer"/>
<field name="PRODUCT_NAME" class="java.lang.String"/>
<field name="PRODUCT_COST" class="java.math.BigDecimal"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="144" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_ID]]></text>
</staticText>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_ID}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="20" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_NAME]]></text>
</staticText>
<textField>
<reportElement x="100" y="20" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_NAME}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="40" width="100" height="20"/>
<textElement/>
<text><![CDATA[PRODUCT_COST]]></text>
</staticText>
<textField>
<reportElement x="100" y="40" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCT_COST}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement x="0" y="60" width="302" height="84"/>
<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="3of9" drawText="false" checksumRequired="false">
<jr:codeExpression><![CDATA[$F{PRODUCT_ID}]]></jr:codeExpression>
</jr:barbecue>
</componentElement>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>

Blank subreport in Jasper report

I have seen quite a few questions on blank subreports but none of them provide the information I need. I have a master report:
<?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="sample_report" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="reportTitle" class="java.lang.String"/>
<parameter name="reportSubTitle" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="65" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="555" height="20"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$P{reportTitle}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="434" y="40" width="80" height="20"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="514" y="40" width="40" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="20" width="555" height="20"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$P{reportSubTitle}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="109" splitType="Stretch">
<subreport isUsingCache="false">
<reportElement x="0" y="0" width="555" height="100" isPrintWhenDetailOverflows="true"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["sample_report_activity_report.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
And a subreport:
<?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="sample_report_activity_report" pageWidth="802" pageHeight="555" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="802" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="SQL">
<![CDATA[SELECT ActivityType, Count, Amount, ActivityDate FROM Activity WHERE ARIID = 1]]>
</queryString>
<field name="ActivityType" class="java.lang.String"/>
<field name="Count" class="java.lang.String"/>
<field name="Amount" class="java.lang.String"/>
<field name="ActivityDate" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="24" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="802" height="20"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Activity Report]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="25" splitType="Stretch">
<staticText>
<reportElement x="12" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[ActivityType]]></text>
</staticText>
<staticText>
<reportElement x="112" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[Count]]></text>
</staticText>
<staticText>
<reportElement x="215" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[Amount]]></text>
</staticText>
<staticText>
<reportElement x="315" y="0" width="100" height="20"/>
<textElement/>
<text><![CDATA[ActivityDate]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="22" splitType="Stretch">
<textField>
<reportElement x="12" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ActivityType}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="115" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{Count}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="215" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{Amount}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="315" y="2" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ActivityDate}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="802" height="20"/>
<textElement textAlignment="Center"/>
<text><![CDATA[--- End of Activity Report ---]]></text>
</staticText>
</band>
</summary>
</jasperReport>
And I have the following Java code:
Map parameters = new HashMap();
parameters.put("reportTitle", "Report");
parameters.put("reportSubTitle", "Activity Date 10/25/2011");
JasperReport jasperReportMain = JasperCompileManager.compileReport("c:\\tempfilepath\\sample_report.jrxml");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReportMain, parameters, con);
JasperExportManager.exportReportToPdfFile(jasperPrint, "c:\\tempfilepath\\SampleReport.pdf");
As far as I can tell I have followed all the previous advice given and I still don't have any data showing up in my subreport when I run the main report. What am I doing wrong?
May be the query in your subreport doesn't return any row. You might try adding No Data band in your subreport, put some Static Text in it, and set the (sub) report property When No Data to No Data Section.
I didn't notice any irregularities from your XML JR code.
First, are you sure your Data Source (database resultset) is returning any results and is set up properly?
I would also recommend installing the IREPORT Designer tool for Jasper Reports. I think the latest version is 4.1.2. This will help you tremendously in both designing and error/exception handling.
I might be wrong because I don't understand much jrxml as a code as I have always developed reports using iReport. Are u passing parameters from main report to subreport? If yes,just check ,by right-click on subreport that whether you have passed the parameters for your subreports.