在Internet Explorer中PDF导出打印 [英] PDF export printing in Internet Explorer

查看:307
本文介绍了在Internet Explorer中PDF导出打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
}

我们正在使用code这样从碧玉应用程序导出PDF文档。

We are using code like this to export a PDF document from a Jasper application.

exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, 
             "this.print({bUI: true,bSilent: false,bShrinkToFit: true});");

添加JavaScript的PDF文档直接发送到打印机。

adds JavaScript to send the PDF document directly to the printer.

预期的行为是一个打印对话框将拿出PDF文档的preVIEW。

The expected behavior is that a print dialog will come up with a preview of the PDF document.

这工作得很好大部分的时间 - 除了我有在Internet Explorer 8和Firefox大约一个问题,每5-6次。

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.

会发生什么事是 - 与PDF文档的打印preVIEW对话不会出现或将其与在preVIEW窗口中的空白文档出现

What happens is - the print preview dialog with the PDF document does not appear or it appears with a blank document in the preview window.

-I've尝试了一些不同的JavaScript(不同的PARAMS到 this.print()通过 exporter.setParameter
-I've尝试设置不同的响应头,如

-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

这似乎是一个IE和FF的问题。有没有人处理这个问题呢?我需要得到它的工作在所有浏览器的100%的时间。也许不同的方法来完成直接发送PDF文档输出到打印机的目标是什么?或第三方库,将跨浏览器的工作?

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 document export directly to the printer? or a third party library that will work across browsers?

推荐答案

也许它没有得到一个机会来更新UI。下面code延迟打印也许能给它所需要的机会。我没有测试,因为我没有你的环境。

Maybe it isn't getting a chance to update the UI. The following code delays the print perhaps giving it the chance it needs. I didn't test as I don't have your environment.

exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT,
    "app.setTimeOut('this.print({bUI: true,bSilent: false,bShrinkToFit: true});',200);")

这篇关于在Internet Explorer中PDF导出打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆