BhavikKama
BhavikKama

Reputation: 8800

ireport generates pdf and html report with different look and feel? Html and Pdf report not generated with same format

I am using jasper report in my liferay custom portlet and i designed my report with ireport 4.7.1 but my problem is why there is vast diffrence in the reports generated with html and with pdf..there is lots of diffrence in rows of reports in html format and pdf format..how can i make both the html and pdf report generated from same jasper file as identical.?i mean with same look and feel.. following are my snippet of html and pdf report

HTML REPORT

HTML REPORT

PDF REPORT

PDF REPORT

following is my jrxml file from which i generate .jasper and then generating above two result.

<?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="Campaign_Advertise_DateRange_Report" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true">
    <property name="ireport.zoom" value="0.9090909090909098"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="Table Dataset 1"/>
    <field name="advertisename" class="java.lang.String"/>
    <field name="camp_name" class="java.lang.String"/>
    <field name="ad_location" class="java.lang.String"/>
    <field name="clicked" class="java.lang.Integer"/>
    <field name="impression" class="java.lang.Integer"/>
    <field name="filter_start_date" class="java.util.Date"/>
    <field name="filter_end_date" class="java.util.Date"/>
    <variable name="CamapignTotal" class="java.lang.Integer" resetType="Group" resetGroup="Campaign Name" calculation="Sum">
        <variableExpression><![CDATA[$F{impression}]]></variableExpression>
    </variable>
    <variable name="CampaignGrandTotal" class="java.lang.Integer" calculation="Sum">
        <variableExpression><![CDATA[$F{impression}]]></variableExpression>
    </variable>
    <group name="Campaign Name">
        <groupExpression><![CDATA[$F{camp_name}]]></groupExpression>
        <groupFooter>
            <band height="21">
                <textField pattern="" isBlankWhenNull="true">
                    <reportElement style="table_TD" x="419" y="0" width="86" height="20"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                        <font isBold="true"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$V{CamapignTotal}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement style="table_TD" x="346" y="0" width="73" height="20"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font isBold="true"/>
                    </textElement>
                    <text><![CDATA[Group Total :]]></text>
                </staticText>
            </band>
        </groupFooter>
    </group>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="114">
            <staticText>
                <reportElement x="136" y="24" width="283" height="67"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="32" isUnderline="true"/>
                </textElement>
                <text><![CDATA[Campaign Reports]]></text>
            </staticText>
            <staticText>
                <reportElement x="0" y="2" width="30" height="20"/>
                <textElement>
                    <font fontName="Times New Roman" isBold="true"/>
                </textElement>
                <text><![CDATA[Date : ]]></text>
            </staticText>
            <textField pattern="MM/dd/yyyy">
                <reportElement x="30" y="2" width="100" height="20"/>
                <textElement textAlignment="Justified">
                    <font fontName="Times New Roman" isUnderline="true"/>
                </textElement>
                <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="0" y="94" width="30" height="20"/>
                <textElement textAlignment="Right">
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[From:]]></text>
            </staticText>
            <staticText>
                <reportElement x="136" y="94" width="19" height="20"/>
                <textElement textAlignment="Right">
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[To:]]></text>
            </staticText>
            <textField>
                <reportElement x="30" y="94" width="96" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{filter_start_date}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="155" y="94" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{filter_end_date}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="419" y="94" width="131" height="20"/>
                <textElement textAlignment="Right">
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Advertise Display Reports]]></text>
            </staticText>
            <image>
                <reportElement x="458" y="8" width="92" height="53"/>
                <imageExpression><![CDATA["D:\\Liferay\\liferay-plugins-sdk-6.1.1-ce-ga2-20120731132656558\\liferay-plugins-sdk-6.1.1\\portlets\\eMenuAdvertise-portlet\\docroot\\img\\eMenuLogo.png"]]></imageExpression>
            </image>
        </band>
    </title>
    <pageHeader>
        <band height="52">
            <staticText>
                <reportElement style="table_TD" mode="Transparent" x="0" y="31" width="100" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Advertise Name]]></text>
            </staticText>
            <staticText>
                <reportElement style="table_TD" mode="Transparent" x="346" y="31" width="73" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Clicked]]></text>
            </staticText>
            <staticText>
                <reportElement style="table_TD" mode="Transparent" x="250" y="31" width="96" height="20" isPrintInFirstWholeBand="true"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[AD Location]]></text>
            </staticText>
            <staticText>
                <reportElement style="table_TD" mode="Transparent" x="100" y="31" width="150" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Campaign Name]]></text>
            </staticText>
            <staticText>
                <reportElement style="table_TD" mode="Transparent" x="419" y="31" width="86" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Times New Roman" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Impression]]></text>
            </staticText>
        </band>
    </pageHeader>
    <detail>
        <band height="21" splitType="Immediate">
            <textField>
                <reportElement style="table_TD" mode="Transparent" x="0" y="-1" width="100" height="22"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
                    <font fontName="Times New Roman"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{advertisename}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement style="table_TD" mode="Transparent" x="250" y="-1" width="96" height="22" backcolor="#FFFFFF"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
                    <font fontName="Times New Roman"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{ad_location}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement style="table_TD" mode="Transparent" x="419" y="-1" width="86" height="22"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
                    <font fontName="Times New Roman"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{impression}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement style="table_TD" mode="Transparent" x="100" y="-1" width="150" height="22"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
                    <font fontName="Times New Roman"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{camp_name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement style="table_TD" mode="Transparent" x="346" y="-1" width="73" height="22"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
                    <font fontName="Times New Roman"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{clicked}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <lastPageFooter>
        <band height="50">
            <staticText>
                <reportElement style="table_TD" x="346" y="0" width="73" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Grand Total :]]></text>
            </staticText>
            <textField isBlankWhenNull="false">
                <reportElement style="table_TD" x="419" y="0" width="86" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{CampaignGrandTotal}]]></textFieldExpression>
            </textField>
        </band>
    </lastPageFooter>
</jasperReport>

Can any one help me out to make both reports look and feel same ?

Upvotes: 1

Views: 3067

Answers (1)

Miguel Garcia
Miguel Garcia

Reputation: 796

The problem in your report seems to be the height of the elements in the Detail Band, they're 22 pixels, and the band is 21, also their top property is -1, i recommend you to make the band bigger (or your controls smaller) and set the Top property to 0, or any positive value.

Upvotes: 2

Related Questions