how to show page number in jasper report

13.4k views Asked by At

How we can show the current page number in jasper sub report ? i have done for only first page with variable like this $V{PAGE_NUMBER} and "("+$V{PAGE_COUNT}+")" but how we can show in all sub reports ?

2

There are 2 answers

1
Nitin Gaur On BEST ANSWER

you have to use page footer band for that,

set the $V{PAGE_NUMBER}'s print when expression to "REPORT" when you have to display total pages and,

$V{PAGE_NUMBER}'s print when expression to "NOW" when you have to display current page number.

TRY This

    <pageFooter>
    <band height="22" splitType="Stretch">

        <textField pattern="M/d/yy h:mm a">
            <reportElement x="580" y="0" width="220" height="20" uuid="941d5c67-e986-4d5b-ba7e-2754f065e008"/>
            <box padding="3"/>
            <textElement textAlignment="Right" verticalAlignment="Middle">
                <font fontName="SansSerif" size="8"/>
            </textElement>
            <textFieldExpression><![CDATA["Printed on : "+new java.util.Date()]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="280" y="1" width="200" height="20" uuid="afe76ecf-00e9-4d52-a00b-44d38dc3aa65"/>
            <box padding="3"/>
            <textElement textAlignment="Center" verticalAlignment="Middle">
                <font fontName="SansSerif" size="8" isBold="true"/>
            </textElement>
            <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}]]></textFieldExpression>
        </textField>
    </band>
</pageFooter>
0
Aslam a On

Follow the below pattern , it should work.

<jasperReport>
<title>
</title>
<detail>
//Here goes all subreports
</detail>
<pageFooter>
<textField evaluationTime="Report">
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</pageFooter>
</jasperReport>