ioeth Posted September 28, 2012 Share Posted September 28, 2012 I know that the JasperReports configuration allows the specification of a maximum number of pages by setting the net.sf.jasperreports.governor.max.pages.enabled and net.sf.jasperreports.governor.max.pages configuration parameters. This isn't exactly ideal for our application, though, as we'd like to be able to specify a maximum number of pages at runtime. Is there any way to leave these two configuration parameters out of the properties file and instead set the maximum number of pages a report can generate at report run time? Thanks in advance! Link to comment Share on other sites More sharing options...
C-Box Posted October 2, 2012 Share Posted October 2, 2012 Hi,I use an own scriptlet for that purpose where the user defined MaxPageLimit is evaluated... so if the report generates more than this value the filling process is canceld with a defined exception. public class AfpsDruckScriptlet extends JRAbstractScriptlet { int maxPages = -1; // -1 means no limit public AfpsDruckScriptlet(int maxPages) { this.maxPages = maxPages; } @Override public void afterPageInit() throws JRScriptletException { Integer aktPageNumber = (Integer) this.getVariableValue("PAGE_NUMBER"); if (this.maxPages>0 && aktPageNumber>this.maxPages) { AfpsBusinessException ex = new AfpsBusinessException("Max PageLimit for printout reached!",AfpsErrors.ACTION_CANCELED); throw new JRScriptletException(ex); } }hthC-Box Link to comment Share on other sites More sharing options...
Solution ioeth Posted October 2, 2012 Author Solution Share Posted October 2, 2012 As it turns out, you can specify this functionality at runtime using code similar to the following:report.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES_ENABLED, Boolean.TRUE.toString()); report.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES, String.valueOf(500));where report is a JasperReport object. The above code snippet would limit the size of a report to 500 pages. Link to comment Share on other sites More sharing options...
ioeth Posted October 2, 2012 Author Share Posted October 2, 2012 Logic similar to this was our first attempt at implementing a report governor. It's also possible to call report.getPages().size() once the report is filled to find out what the page count is and limit that way. Link to comment Share on other sites More sharing options...
oroset Posted November 4, 2014 Share Posted November 4, 2014 Hi, Can we do the same thing with the php api ?report.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES_ENABLED, Boolean.TRUE.toString());report.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES, String.valueOf(500));? 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