Jump to content
Changes to the Jaspersoft community edition download ×

Setting max report pages at runtime in code, rather than in JasperReports config


ioeth
Go to solution Solved by ioeth,

Recommended Posts

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

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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);
    }    
  }


hth

C-Box

Link to comment
Share on other sites

  • Solution

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

  • 2 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...