Hello
My reports are configured to create 'No Pages' when no Data are available. Usually, when printed directly with Jasper:
JasperPrint print = JasperFillManager.fillReport(JASPER_PATH + REPORT + ".jasper", mapParameters, this.dbConnection); PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); printRequestAttributeSet.add(MediaSizeName.ISO_A4); printRequestAttributeSet.add(OrientationRequested.PORTRAIT); PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet(); printServiceAttributeSet.add(new PrinterName("PRINTERNAME", null)); exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet); exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE); exporter.exportReport();
No output gets generated and no pages get printed.
But, when printed indirectly through a pdf-file:
JasperPrint print = JasperFillManager.fillReport(reportFileName, parameterMap, db.getConnection()); JasperExportManager.exportReportToPdfFile(print, cachePath + options+".pdf")
With the same reportfile, in this case an empty PDF-File with a blank page gets generated. This is kind of undesireable and I would prefer to not generate a file at all in this case. Even better would be to get an exception which tells me that the report has no pages.
Is there a solution for this?
1 Answer:
Posted on March 9, 2011 at 10:57pm
I found the solution. Just in case someone has a similar problem:
JasperPrint print = JasperFillManager.fillReport(reportFileName, parameterMap, db.getConnection()) if(print.getPages().size() > 0) { // we have pages ... do printing here } else{ // no pages, throw exeption to handle this case }