1

Possible Duplicate:
how to open print dialog after pdf generated

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

JRPdfExporter pdfExporter = new JRPdfExporter();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
pdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, byteArrayOutputStream);

if (isPrint) {
    pdfExporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print();");
}

try {
    pdfExporter.exportReport();
} catch (JRException e) {
    log.error("Exception exporting pdf report");
    throw new PrintExportException(e);
}

return byteArrayOutputStream;

This is a snippet of a Java method that returns a pdf document using JRPdfExporter - it works fine in all browsers except for a problem with IE and FF. If the document is to be sent directly to the printer the if (isPrint) statement sets a JavaScript that prints the document instead of presenting it for download.

In IE and FF - maybe one out of 20 times this does not work. The print preview dialog box just does not come up. Afterwards, I can try generating the document again and it works, so it seems like an intermittent problem. No console errors.

Any problems in this code? I haven't been able to pin it down.

Community
  • 1
  • 1
user619804
  • 2,286
  • 12
  • 46
  • 71
  • You should read [how to open print dialog after pdf generated](http://stackoverflow.com/questions/8733276/how-to-open-print-dialog-after-pdf-generated) post carefully. – Alex K Nov 09 '12 at 09:19

0 Answers0