Jump to content
JasperReports Library 7.0 is now available ×

NoPages-Option creates empty PDF-File

Go to solution Solved by Guest,

Recommended Posts


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(); [/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

  • Replies 1
  • Created
  • Last Reply
  • Solution

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

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...