Java - How to remove a page in jasper reports that

2019-03-03 17:43发布

问题:

I have been seeing a strange issue in jasper. It is when any of my columns are overflowing to the next page. A Page prior is coming blank with only headers. I am not sure if it is a Jasper issue. Now i am trying to remove such pages from Java. I do know how to remove a page but how do i remove a page with only headers available condition.I am not able to get them.

Below is the code i have been trying. This does remove the page. But i want to identify the page with only header and no data and remove them:

for (Iterator<JRPrintPage> i=jasperPrint.getPages().iterator(); i.hasNext();) 
                {
                      JRPrintPage page = i.next();
                      if (page.getElements().size() == 0)
                      {
                          System.out.println("We have a blank page here");
                          i.remove();
                      }
                  }

Please guide. Much appreciated.