Break the PDF document after 100 pages

2019-03-01 10:19发布

问题:

I am working with JasperReports and iReport tool. One of the requirements the client wants is that the PDF file will be generated to a 100 page document only.

Could you please help me? How can I generated the 100 page PDF document?

回答1:

As @WEG mentioned in the answer for JasperReport size limit question it can be done with help of this parameters:

  • net.sf.jasperreports.governor.max.pages.enabled - a flag indicating whether the governor that checks if a report exceeds a specified limit of pages is turned on. With this property enabled, the JR engine will stop the report execution if the number of pages becomes greater than a custom given value;
  • net.sf.jasperreports.governor.max.pages - if the governor that checks if a report exceeds a specified limit of pages is turned on, this property will indicate the maximum number of pages allowed to be ran, in order to prevent a memory overflow error. If the number of pages in the report becomes greater than this value, the report execution will be stopped;
  • REPORT_MAX_COUNT - an integer allowing limit the datasource size.


回答2:

In the iReport you can find a built in variable PAGE_COUNT. For every element in the detail band you can put the following in the "Print when expression" textbox:

Boolean.valueOf($V{PAGE_COUNT}.intValue() < 100)

This will stop printing after page number 100.