title: Generating PDF from subreport
body: <p>I have one main report like this in jasper</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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="Allergy" language="groovy" pageWidth="595" pageHeight="842" columnWidth="503" leftMargin="72" rightMargin="20" topMargin="20" bottomMargin="20" isTitleNewPage="true" isSummaryNewPage="true" isSummaryWithPageHeaderAndFooter="true" isFloatColumnFooter="true" isIgnorePagination="true" &gt; &lt;property name="ireport.zoom" value="1.0"/&gt;
      &lt;property name="ireport.x" value="0"/&gt;
      &lt;property name="ireport.y" value="723"/&gt;
      &lt;parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"&gt;
          &lt;defaultValueExpression&gt;&lt;![CDATA["D:\\FTP\\JRXML\\PatientConsultantReport\\"]]&gt;&lt;/defaultValueExpression&gt;
      &lt;/parameter&gt;
      &lt;queryString language="SQL"&gt;
          &lt;![CDATA[select *  from VIEW_tbPatientAllergy]]&gt;
      &lt;/queryString&gt;
      &lt;field name="PatientAllergyIDP" class="java.lang.Integer"/&gt;
      &lt;field name="CitizenIDF" class="java.lang.Integer"/&gt;
      &lt;field name="AllergyNameIDF" class="java.lang.Integer"/&gt;
      &lt;field name="AllergyReactionIDF" class="java.lang.Integer"/&gt;
      &lt;field name="Severity" class="java.lang.Integer"/&gt;
      &lt;field name="OnsetDate" class="java.lang.String"/&gt;
      &lt;field name="Status" class="java.lang.Integer"/&gt;
      &lt;field name="Remarks" class="java.lang.String"/&gt;
      &lt;field name="IsDirect" class="java.lang.Boolean"/&gt;
      &lt;field name="EncounterIDF" class="java.lang.Integer"/&gt;
      &lt;field name="Created" class="java.sql.Timestamp"/&gt;
      &lt;field name="CreatedByIDF" class="java.lang.Integer"/&gt;
      &lt;field name="LastModified" class="java.sql.Timestamp"/&gt;
      &lt;field name="LastModifiedByIDF" class="java.lang.Integer"/&gt;
      &lt;field name="AllergyName" class="java.lang.String"/&gt;
      &lt;field name="AllergyReaction" class="java.lang.String"/&gt;
      &lt;field name="AllergyType" class="java.lang.String"/&gt;
      &lt;background&gt;
          &lt;band splitType="Stretch"/&gt;
      &lt;/background&gt;
      &lt;title&gt;
          &lt;band height="40" splitType="Stretch"/&gt;
      &lt;/title&gt;
      &lt;pageHeader&gt;
          &lt;band height="5" splitType="Stretch"/&gt;
      &lt;/pageHeader&gt;
      &lt;columnHeader&gt;
          &lt;band height="29" splitType="Stretch"/&gt;
      &lt;/columnHeader&gt;
      &lt;detail&gt;
  
  
          &lt;band height="50"&gt;
  
              &lt;subreport&gt;
  
                  &lt;reportElement  x="-66" y="0" width="582" height="39"/&gt;
                  &lt;connectionExpression&gt;&lt;![CDATA[$P{REPORT_CONNECTION}]]&gt;&lt;/connectionExpression&gt;
                  &lt;subreportExpression&gt;&lt;![CDATA["D:\\FTP\\JRXML\\PatientConsultantReport\\OrderSet.jasper"]]&gt;&lt;/subreportExpression&gt;
  
              &lt;/subreport&gt;
  
          &lt;/band&gt;
      &lt;/detail&gt;
      &lt;columnFooter&gt;
          &lt;band height="36" splitType="Stretch"/&gt;
      &lt;/columnFooter&gt;
      &lt;pageFooter&gt;
          &lt;band height="27" splitType="Stretch"/&gt;
      &lt;/pageFooter&gt;
      &lt;summary&gt;
          &lt;band splitType="Stretch"/&gt;
      &lt;/summary&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>And subreport like this</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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="OrderSet" pageWidth="595" pageHeight="842" columnWidth="503" leftMargin="72" rightMargin="20" topMargin="20" bottomMargin="20" &gt;
      &lt;property name="ireport.zoom" value="1.0"/&gt;
      &lt;property name="ireport.x" value="0"/&gt;
      &lt;property name="ireport.y" value="0"/&gt;
      &lt;queryString&gt;
          &lt;![CDATA[select * from view_tbPatientOrderSet]]&gt;
      &lt;/queryString&gt;
      &lt;field name="PatientOrderSetIDP" class="java.lang.Integer"/&gt;
      &lt;field name="EncounterIDF" class="java.lang.Integer"/&gt;
      &lt;field name="ServiceMapIDF" class="java.lang.Integer"/&gt;
      &lt;field name="ServiceIDF" class="java.lang.Integer"/&gt;
      &lt;field name="OrderDate" class="java.lang.String"/&gt;
      &lt;field name="Quantity" class="java.math.BigDecimal"/&gt;
      &lt;field name="ReferToIDF" class="java.lang.Integer"/&gt;
      &lt;field name="IsExternal" class="java.lang.Boolean"/&gt;
      &lt;field name="ExternalCareProviderIDF" class="java.lang.Integer"/&gt;
      &lt;field name="ExternalCareProvider" class="java.lang.String"/&gt;
      &lt;field name="OrderStatus" class="java.lang.Boolean"/&gt;
      &lt;field name="EncounterServiceIDF" class="java.lang.Integer"/&gt;
      &lt;field name="Remarks" class="java.lang.String"/&gt;
      &lt;field name="Created" class="java.sql.Timestamp"/&gt;
      &lt;field name="CreatedByIDF" class="java.lang.Integer"/&gt;
      &lt;field name="LastModified" class="java.sql.Timestamp"/&gt;
      &lt;field name="LastModifiedByIDF" class="java.lang.Integer"/&gt;
      &lt;field name="ServiceName" class="java.lang.String"/&gt;
      &lt;field name="FirstName" class="java.lang.String"/&gt;
      &lt;field name="MiddleName" class="java.lang.String"/&gt;
      &lt;field name="FamilyName" class="java.lang.String"/&gt;
      &lt;field name="PatientProfileIDF" class="java.lang.Integer"/&gt;
      &lt;field name="PriceListIDP" class="java.lang.Integer"/&gt;
      &lt;field name="Rate" class="java.math.BigDecimal"/&gt;
      &lt;field name="CitizenIDF" class="java.lang.Integer"/&gt;
      &lt;field name="EnrolmentID" class="java.lang.String"/&gt;
      &lt;field name="CitizenName" class="java.lang.String"/&gt;
      &lt;field name="ServiceCategory" class="java.lang.String"/&gt;
      &lt;background&gt;
          &lt;band splitType="Stretch"/&gt;
      &lt;/background&gt;
      &lt;title&gt;
          &lt;band height="20" splitType="Stretch"&gt;
              &lt;staticText&gt;
                  &lt;reportElement  x="4" y="0" width="65" height="20"/&gt;
                  &lt;textElement verticalAlignment="Middle"&gt;
                      &lt;font size="15" isBold="true"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[Order Set]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
          &lt;/band&gt;
      &lt;/title&gt;
      &lt;columnHeader&gt;
          &lt;band height="30" splitType="Stretch"&gt;
              &lt;line&gt;
                  &lt;reportElement  x="3" y="27" width="457" height="1"/&gt;
              &lt;/line&gt;
              &lt;staticText&gt;
                  &lt;reportElement  x="3" y="5" width="52" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;text&gt;&lt;![CDATA[Order Date]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement  x="73" y="5" width="68" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;text&gt;&lt;![CDATA[Service Name]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement  x="157" y="5" width="41" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;text&gt;&lt;![CDATA[Quantity]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement  x="231" y="5" width="50" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;text&gt;&lt;![CDATA[IsExternal]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement  x="301" y="5" width="85" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;text&gt;&lt;![CDATA[Care Professional]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement  x="415" y="5" width="44" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;text&gt;&lt;![CDATA[Remarks]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
          &lt;/band&gt;
      &lt;/columnHeader&gt;
      &lt;detail&gt;
          &lt;band height="25" splitType="Stretch"&gt;
              &lt;textField&gt;
                  &lt;reportElement  x="3" y="3" width="66" height="18"/&gt;
                  &lt;textElement/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{OrderDate}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement  x="73" y="3" width="84" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{ServiceName}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement  x="167" y="3" width="58" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{Quantity}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement  x="231" y="3" width="67" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{IsExternal}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement  x="301" y="3" width="115" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[($F{FirstName}!=null?$F{FirstName}:"")+" "+($F{MiddleName}!=null?$F{MiddleName}:"")+" "+($F{FamilyName}!=null?$F{FamilyName}:"")]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement  x="415" y="3" width="60" height="20"/&gt;
                  &lt;textElement/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{Remarks}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
      &lt;columnFooter&gt;
          &lt;band height="23" splitType="Stretch"/&gt;
      &lt;/columnFooter&gt;
      &lt;pageFooter&gt;
          &lt;band height="18" splitType="Stretch"/&gt;
      &lt;/pageFooter&gt;
      &lt;summary&gt;
          &lt;band splitType="Stretch"/&gt;
      &lt;/summary&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>I want to generate pdf from <em>Java</em> code</p>
  
  <pre><code>String jrxmlFileLocation = "D:\\OrderSet.jrxml";
  String jasperFileLocation = "D:\\OrderSet.jasper";
  String outputPDFFile = "D:\\VisitsSummaryReport.pdf";
  JasperCompileManager.compileReportToFile(jrxmlFileLocation, jasperFileLocation);
  JasperCompileManager.compileReportToFile("D:\\Final_PatinetConsultation.jrxml", "D:\\Final_PatinetConsultation.jasper");
  </code></pre>
  
  <p>It compile successfully and how to generate pdf file from this report please help me in this code.</p>
  
  <p>I see this link but does not understand
  <a href="https://stackoverflow.com/questions/20092010/jasper-sub-report-not-shown-in-pdf">enter link description here</a></p>
  
  <p>I use result set like this</p>
  
  <pre><code>String condition = "data = "+data;
  PreparedStatement psOrderSet = conn.prepareCall("{call Sp_tbPatientOrderSet_GetAll(?)}",ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
  psOrderSet.setString(1,condition);
  ResultSet rsOrderSet = psOrderSet.executeQuery();
  rsOrderSet.last();
  int lengthOrderSet=rsOrderSet.getRow();
  rsOrderSet.beforeFirst();
  </code></pre>
  
  <p>And how to pass ResultSet to the sub report for fill the data.</p>