JSF/Seam: How to download and print a dynamically generated PDF file without user intervention?

蹲街弑〆低调 提交于 2019-12-05 14:55:39
BalusC

However, I have no idea how to get the PDF into the iframe via the HttpServletResponse (in Java)

Let the <iframe src> point to a servlet URL which gets an InputStream of the PDF and writes it to the OutputStream of the response. You can if necessary pass JSF bean properties as additional GET parameters so that you can control the PDF generation.

<iframe src="pdfServlet?foo=#{bean.foo}&amp;bar=#{bean.bar}"></iframe>

The doGet() method of the servlet in question can look like this:

String foo = request.getParameter("foo");
String bar = request.getParameter("bar");

response.setContentType("application/pdf");

InputStream input = generatePdfSomehowBasedOn(foo, bar);
OutputStream output = response.getOutputStream();
// Now just write input to output.

much less how to automatically call print() on the iframe once the pdf has been loaded.

Hook a function on <iframe onload>. You however need to take browser specific behaviours into account. More hints can be found in this question: How do I print an IFrame from javascript in Safari/Chrome

Enrique San Martín

This is not an answer to your question, but you can by pass the print dialog in chrome using "kiosk" mode (skipping printing dialog) see:

How to disable print preview on Google Chrome ver 38?

I hope that works for you :)

quoted from answer:

The command-line argument --disable-print-preview works on the newest version of Chrome, I've just tested it myself.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!