JasperReport with spring MVC : print report on cli

2019-03-30 09:13发布

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);

1条回答
放荡不羁爱自由
2楼-- · 2019-03-30 09:51

You can create an object in HTML page which hold PDF & then print it using print() method or use java.awt.print.PrinterJob. See below examples.

Hope this helps you

查看更多
登录 后发表回答