jim.lemaire Posted December 23, 2016 Share Posted December 23, 2016 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.0I'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 More sharing options...
hozawa Posted January 2, 2017 Share Posted January 2, 2017 I had a similar situation but instead of trying to modify JasperPrint object after it was created, I just passed the starting page number as a parameter for pages after the first. Link to comment Share on other sites More sharing options...
jim.lemaire Posted January 2, 2017 Author Share Posted January 2, 2017 I did it that way at first but only to realize that some of my reports may contain more than 1 page, then you only know that once it's compiled so it "falsify" the counter Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now