Guest Posted March 9, 2011 Share Posted March 9, 2011 HelloMy 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(); [/code]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") [/code]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? Link to comment Share on other sites More sharing options...
Solution Guest Posted March 10, 2011 Solution Share Posted March 10, 2011 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}[/code] 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