saiyan101
saiyan101

Reputation: 620

Java: blank page issue on jasper report

I have a report that has 2 sub reports in the detail band.I would like to add in a paging parameter in the column footer but when I preview my report it gives me a blank page at the end. I have set the following for my Sub Report block in the their property window.

Print Repeated Values checked

Remove Line When Blank checked

Upvotes: 2

Views: 10483

Answers (3)

Ciro Hidalgo
Ciro Hidalgo

Reputation: 121

The response is at this link http://mattjiang.blogspot.com/2007/05/easy-way-to-remove-blank-page-generated.html

private void removeBlankPage(List<JRPrintPage> pages) {
  for (Iterator<JRPrintPage> i = pages.iterator(); i.hasNext();) {
    JRPrintPage page = i.next();
    if (page.getElements().size() == 0) {
      i.remove();
    }
  }
}

Upvotes: 2

Navankur Chauhan
Navankur Chauhan

Reputation: 417

An easy way to remove blank page generated by JasperReports.

If your JasperReports report has one more sub-reports and it was generated as PDF file. In some circumstances, a blank page might be found within PDF file. Here is my solution to easily remove it.

private void removeBlankPage(List<JRPrintPage> pages) {

      for (Iterator<JRPrintPage> i=pages.iterator(); i.hasNext();) {
          JRPrintPage page = i.next();
          if (page.getElements().size() == 0)
              i.remove();
      }
  }

This method should be called before you flush your JasperPrint instance to PDF.

Followed with the sample code, it would be better to know the object hierarchy of JasperPrint.

  1. A JasperPrint has one or more JRPrintPage, you can get it via getPages() method of JasperPrint. It returns a List of JRPrintPage. If you have three elements, then your printer will print 3 pages.
  2. A JRPrintPage has one ore more JRPrintElement, each element might be a string of text, or a picture, or a rectangle, etc. You can change its position or content dynamically, or even add new JRPrintElement into JRPrintPage.

CREDITS : http://mattjiang.blogspot.in/2007/05/easy-way-to-remove-blank-page-generated.html

Upvotes: 0

ajaristi
ajaristi

Reputation: 982

With the usage of this link http://mattjiang.blogspot.com/2007/05/easy-way-to-remove-blank-page-generated.html, I could navigate through the generated jasper and I found "trash elements" in my report:

int actualPage = 1;
for (Iterator<JRPrintPage> i=jasperPrint.getPages().iterator(); i.hasNext();) {
  JRPrintPage page = i.next();
  System.out.println(String.format("Page: %s, size: %s", actualPage, page.getElements().size()));
     for (Object element : page.getElements()) {
        System.out.println("Element: " + element);
        if (element instanceof JRTemplatePrintRectangle) {
            JRTemplatePrintRectangle rectangle = (JRTemplatePrintRectangle) element;
            System.out.println(String.format("Rectangle: Key: %s", rectangle.getKey()));
        }
    }
     actualPage++;
}

Upvotes: 2

Related Questions