Jump to content
We've recently updated our Privacy Statement, available here ×

Jasper PDF export printing in Internet Explorer


qt4x11

Recommended Posts

 

protected static byte[] exportReportToPdf(JasperPrint jasperPrint) 
                                                      throws JRException {
  JRPdfExporter exporter = new JRPdfExporter();       
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
  exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
  exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
  exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, 
              "this.print({bUI: true,bSilent: false,bShrinkToFit: true});");
 
  exporter.exportReport();        
  return baos.toByteArray();
}
 
We are using code like this to export a pdf from a jasper application.
 
The line
 
exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, 
             "this.print({bUI: true,bSilent: false,bShrinkToFit: true});");
 
adds Javacript to send the pdf document directly to the printer.
 
The expected behavior is that a print dialog will come up with a preview of the pdf document.
 
This works fine most of the time - except I am having problems about one out of every 5-6 times in Internet Explorer 8 and Firefox.
 
What happens is - the print preview dialog with the pdf does not appear or it appears with a blank document in the preview window.)
 
-I've tried a number of different javascripts (different params to this.print() via exporter.setParameter -I've tried setting different response headers such as
 
response.setContentType("application/pdf");
response.setHeader("Content-disposition","inline;  filename="" 
                   + reportName 
                   + """);
response.setContentLength(baos.size());
 
these did not seem to help
 
This seems to be an IE and FF issue. Has anyone ever dealt with this problem? I need to get it to work across all browsers 100% of the time. Perhaps a different approach to accomplish the goal of sending the pdf export directly to the printer? or a third party library that will work across browsers? Thanks for any advice.
Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • 1 year later...

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