Search code examples
jasper-reportssubreport

how to show page number in jasper report


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 ?


Solution

  • 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>