How to set dynamically isIgnorePagination in jasper report?

I have a jasper file that I export to PDF and Excel, at the moment I use only one jasper, I want the exported PDF report to be "isIgnorePagination =" true ", and for the Excel report should be" isIgnorePagination = " false '??

How to install from java code?

+5
source share
3 answers

You need to know at run time if you export to Excel or PDF what you need to know.

As an example:

public void generateReport(JasperPrint report, boolean isExcel, String saveTo){
  JRExporter exporter = null;
  if (isExcel) {
    exporter = new JRXlsExporter();
    exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
    exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
    exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
    //we set the one page per sheet parameter here
    exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
  } else {
    exporter = new JRPdfExporter();     
  }
  exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);124
  exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, saveTo);
  export.exportReport();
}
+5
source

According to the reference to the JasperReports sample :

[ isIgnorePagination jrxml] IS_IGNORE_PAGINATION.

, :

final Map<String, Object> fillingParameters = new HashMap<>();
if (exportType == ExportType.XLS) {
    fillingParameters.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE);
}
final JasperPrint print = JasperFillManager.fillReport(jasperReport, fillingParameters, dataSource);
+1

I found a solution for this.

my code is:

paramaters.put("fromDate", fromDate);
paramaters.put("toDate", toDate);
if (!output.equals("pdf"))
{
    paramaters.put("IS_IGNORE_PAGINATION", true);
}
else
    paramaters.put("IS_IGNORE_PAGINATION", false);

JasperPrint jasperPrint = null;
jasperPrint = JasperFillManager.fillReport(CompiledReport,paramaters, connection);

if (output.equals("html")) {
    generateHtmlResponse(response, jasperPrint);
} else if (output.equals("pdf")) {
    generatePdfResponse(response, jasperPrint);
} else if(output.equals("excel")) {
    generateXLResponse(response, jasperPrint);
}
0
source

All Articles