生成pdf后如何打开打印对话框? [英] How to open print dialog after pdf generated?
问题描述
我编写了一些动态生成 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.
我现在要做的是直接打开打印机对话框.因此,当我调用 reports/reportGenerator?param=dialy
和 pdf 文件完全生成后,打开打印机对话框.那可能吗?(我知道打印机对话框不能跳过)
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 K 我找到了答案:
Thanks to Alex K I found the answer:
根据JRPdfExporterParameter.html#PDF_JAVASCRIPT
您可以在生成 pdf 时使用 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屋!