Ashish Banker
Ashish Banker

Reputation: 2473

Jasper report blank page

My jrxml and java code below . I am trying to create report with some text and values . However blank report is generated . I am pasing map to fill the report as parameter . I have to add 4-5 static lines and then one dynamic variable . I have added these thing in detailed band .whats wrong

    <?xml version="1.0" encoding="UTF-8"  ?>
    <!-- Created with iReport - A designer for JasperReports -->
    <!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
    <jasperReport
             name="Untitled_report_2"
             columnCount="1"
             printOrder="Vertical"
             orientation="Portrait"
             pageWidth="595"
             pageHeight="842"
             columnWidth="535"
             columnSpacing="0"
             leftMargin="30"
             rightMargin="30"
             topMargin="20"
             bottomMargin="20"
             whenNoDataType="NoPages"
             isTitleNewPage="false"
             isSummaryNewPage="false">
        <property name="ireport.scriptlethandling" value="0" />
        <property name="ireport.encoding" value="UTF-8" />
        <import value="java.util.*" />
        <import value="net.sf.jasperreports.engine.*" />
        <import value="net.sf.jasperreports.engine.data.*" />


        <field name="Field" class="java.lang.String"/>

            <background>
                <band height="0"  isSplitAllowed="true" >
                </band>
            </background>
            <title>
                <band height="50"  isSplitAllowed="true" >
                </band>
            </title>
            <pageHeader>
                <band height="50"  isSplitAllowed="true" >
                </band>
            </pageHeader>
            <columnHeader>
                <band height="30"  isSplitAllowed="true" >
                </band>
            </columnHeader>
            <detail>
                <band height="100"  isSplitAllowed="true" >
                    <staticText>
                        <reportElement
                            x="20"
                            y="10"
                            width="180"
                            height="30"
                            key="staticText-1"/>
                        <box></box>
                        <textElement>
                            <font/>
                        </textElement>
                    <text><![CDATA[4-5 lines text]]></text>
                    </staticText>
                    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                        <reportElement
                            x="20"
                            y="40"
                            width="60"
                            height="20"
                            key="textField-1"/>
                        <box></box>
                        <textElement>
                            <font/>
                        </textElement>
                    <textFieldExpression   class="java.lang.String"><![CDATA[$F{Field}]]></textFieldExpression>
                    </textField>
                    <staticText>
                        <reportElement
                            x="20"
                            y="70"
                            width="160"
                            height="30"
                            key="staticText-2"/>
                        <box></box>
                        <textElement>
                            <font/>
                        </textElement>
                    <text><![CDATA[4-5 lines text]]></text>
                    </staticText>
                </band>
            </detail>
            <columnFooter>
                <band height="30"  isSplitAllowed="true" >
                </band>
            </columnFooter>
            <pageFooter>
                <band height="50"  isSplitAllowed="true" >
                </band>
            </pageFooter>
            <lastPageFooter>
                <band height="50"  isSplitAllowed="true" >
                </band>
            </lastPageFooter>
            <summary>
                <band height="50"  isSplitAllowed="true" >
                </band>
            </summary>
    </jasperReport>

Java code :

    InputStream fileInput = getApplicationContext().getResource("/WEB-INF/reports/myjrxml.jrxml").getInputStream();
    JasperReport jasperReport = JasperCompileManager.compileReport(fileInput);
    HashMap map = new HashMap();
    map.put("Field", "test");
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map);
    byte[] output1 = JasperExportManager.exportReportToPdf(jasperPrint); 
    String filename = "d:/test.pdf";
    FileOutputStream fo = new FileOutputStream(filename);
    fo.write(output1);
    fo.close();

Upvotes: 5

Views: 9069

Answers (3)

Prabhu
Prabhu

Reputation: 1

I have encountered the empty page issue several times when calling a subreport from the main Jasper report. Please ensure that the subreport is called from the group header and refrain from calling it from the group footer. This solution has proven effective for me.

Upvotes: 0

salerokada
salerokada

Reputation: 383

I had also blank page (pdf). Even for the simplest report.
Until I sent empty datasource (new JREmptyDataSource())!
This solved my problem:

Map<String, Object> param = new HashMap<>();
param.put("SOME_PARAM","something");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, param, new JREmptyDataSource());

Explanation here.

By default, when no datasource info is present in a report, JR generates no pages.

Upvotes: 3

Tim
Tim

Reputation: 1685

You are confusing the report data with parameters. I don't see that you have any report data, which is why you are getting an empty report. Further, you are filling a parameter named "Field" instead of the actual report data. So you either need to create a parameter called "Field" in your report, and then refer to it in the detail band, OR you need to pass the report data into your report something like

JRBeanCollectionDataSource data = new JRBeanCollectionDataSource(dataSet);
jasperPrint = JasperFillManager.fillReport(jasperReport, parameterMap, data);

where dataSet is a collection, such as List<?>. Within the List, you would have an object where one of the properties is Field.

Upvotes: 4

Related Questions