Jump to content
We've recently updated our Privacy Statement, available here ×

Add TextElement to PageFooter programatically


jim.lemaire

Recommended Posts

Hi,

I'm currently trying to add a text element programatically in a JRPrintPage object.

I've a working full report which is build by concatenating multiple reports, I've had to do this in order to mix portrait and landscape report.

My problem is that I have to insert page number inside the pageFooter of those page after filling these reports. I have the total number of page and also the number of the current page.

JasperReports version : 6.2.0

I've tried the following without any success : 

private void drawPageNumbers(List<JasperPrint> listJasperPrint, int totalPages) throws JRException {        int pageCount = 0;        int posY = 0;        int posX = 0;        for (JasperPrint jasperPrint : listJasperPrint) {            if (jasperPrint.getOrientationValue() == OrientationEnum.PORTRAIT) {                posY = 9;                posX = 273;            }            //ToDo            /*if (jasperPrint.getOrientationValue() == OrientationEnum.LANDSCAPE) {                posY = 558;                posX = 717;            }*/            for (JRPrintPage jrPrintPage : jasperPrint.getPages()) {                pageCount++;                //get Footer                JRPrintElement jrPrintElement = jrPrintPage.getElements().get(jrPrintPage.getElements().size()-1);                //JRPrintText textPageNumber = new JRTemplatePrintText(new JRTemplateText(originFooter, jasperPrint.getDefaultStyleProvider()));                JRBasePrintText textPageNumber = new JRBasePrintText(jasperPrint.getDefaultStyleProvider());                textPageNumber.setX(posX);                textPageNumber.setY(posY);                textPageNumber.setWidth(54);                textPageNumber.setHeight(12);                textPageNumber.setText(pageCount + " / " + totalPages);                jrPrintElement.addElement(textPageNumber);            }        }[/code]

The jrxml structure of the PageFooter is the following:

<pageFooter> <band>  <frame>   <!-- various text element -->  </frame> </band></pageFooter>[/code]

Hope someone can help me, if you need more informations, don't hesitate to ask them ! 

Thanks in advance, 

Jim

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...