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.
8 comments:
you are my hero for today, thank you so very much
it works perfectly!!!
Worked, but didn't help in the end as my "empty" pages are not actually totally empty, they have just a page header and footer. And the problem is that page numbers appear in the footer: so page 5 is followed by page 7, when 6 was removed.
Fixed my problem the right way: there was some space below content in one band which I removed and so that this spacing is not wrapped to next page and causing an empty page.
Can you please let me know where exactly i should call this function (removeblankpages()) to avoid a empty page?
i checked in Template & JAR also but there is no JasperPrint Function .
Thanks sir it was great solution . i try hundred way to solve my problem . this is one help ful ...
thanks alot..
it's work perfectly! so much thank you :)
Hello! How to use it? Where is place to put this code?
Post a Comment