pdf生成后如何打开打印对话框? [英] How to open print dialog after pdf generated?

查看:443
本文介绍了pdf生成后如何打开打印对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些生成动态PDF文件的动作。类似于:reports / reportGenerator.action

I wrote some actions which generates dynamically PDF files. something like: reports/reportGenerator.action

当我打电话给 reports / reportGenerator?param = dialy 它会打开在弹出窗口中生成pdf,然后我可以按打印按钮打开打印机对话框并打印出来。

when I call reports/reportGenerator?param=dialy it will open the generated pdf in a popup, and then I can press the print button to open the printer dialog and print it.

我现在要做的是打开打印机对话框直。因此,当我在完全生成pdf文件后调用 reports / reportGenerator?param = dialy 时,打开打印机对话框。那可能吗? (我知道不能跳过打印机对话框)

what I want to do now is to open the printer dialog directly. so when I call reports/reportGenerator?param=dialy and after the pdf file is fully generated, open the printer dialog. is that possible? (I know the printer dialog can not be skipped)

更多信息:
操作是这样的:

more info: action is something like this:

sout = response.getOutputStream();
response.setContentType("application/pdf");
response.setHeader("Content-disposition","inline; filename=\"myReport.pdf\"");
sout.write(pdfBytes);
sout.flush();
sout.close();


推荐答案

感谢Alex KI找到答案:

Thanks to Alex K I found the answer:

根据 JRPdfExporterParameter.html#PDF_JAVASCRIPT

您可以使用 PDF_JAVASCRIPT 属性添加javascript到生成它时的pdf。

you can use PDF_JAVASCRIPT property to add javascript to the pdf when you generate it.

所以我添加了

JRPdfExporter exporter = new  JRPdfExporter();
exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print();");

导出PDF并且工作正常

when exporting PDF and it worked

这篇关于pdf生成后如何打开打印对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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