I’m new to JasperReports and find myself getting pretty lost with it. I’ve got a webapp in JSF that I want to use to print a PDF. I’ve built the report, and am able to successfully compile and fill it with all my parameters. However, I’m lost on the actual output portion. I’d like it go to a printer as a PDF. I don’t care about ever seeing it on screen, straight to printer would be the ideal (from the server would be ideal, but client would also be fine as we could setup the clients to print as necessary (it’s an internal app)).
Share
You can’t do it with plain HTML/CSS/JS. As JSF is basically just a HTML/CSS/JS code generator, it can’t do any magic for you. Closest what you can get is JavaScript’s
window.print(), but that would still show the user the printer settings and such (basically, it does the same asCtrl+P).Your best bet is to create an Applet which uses the
javax.printAPI and then embed that Applet in your JSF page by HTML<applet>or<object>tag.If you can live with seeing it straight on screen and delegating the print job to the enduser itself, then you can send a PDF file to screen by JSF as follows:
I have never worked with JasperReports, so the
yourJasperReportsClass.writePdfTo()was just a random guess, but the hint should be clear enough. You basically need to instruct it to write the PDF to the response body.Update: as per the comments, that printer is actually connected to the server, not to the client and you actually want to let the server print it to its printer. In that case, just use the
javax.printAPI. At the bottom of that document you can find some code examples. Here’s an extract of relevance:It’s not relevant if the above code called by a JSF managed bean. It’s after all just Java. You might only want to modify the
DocFlavorand other settings.