I am developping a Spring MVC - Angularjs application.
I need to print reports, I chose JasperReport to do that.
Before I move on, I want to know if I can generate a report, then directly print it on the default printer set up on the client computer (printer which can change according to users) without displaying it on screen.
I have been looking for answers on this specific need, but couldn't find any.
If anyone knows about it....
Source to generate report and print it:
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("Title", "My Report");
InputStream reportStream = this.getClass().getResourceAsStream(TEMPLATE);
JasperDesign jd = JRXmlLoader.load(reportStream);
JasperReport jr = JasperCompileManager.compileReport(jd);
JasperPrint jp = JasperFillManager.fillReport(jr, params, datasource.getDataSource());
JasperPrintManager.printReport(jp, false);
You can create an object in HTML page which hold PDF & then print it using
print()
method or usejava.awt.print.PrinterJob
. See below examples.Hope this helps you