4

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);
user1260928
  • 3,269
  • 9
  • 59
  • 105
  • Have u tried some code to achieve this ? Add it to ur post. – OO7 Mar 10 '15 at 10:27
  • No, because my dev server is actually on local (same computer as the client), for development purposes. I can't use a server on a different computer for now. And I believe that this could be a problem. – user1260928 Mar 10 '15 at 10:31
  • Do u want Java code to generate report in some format or print Or both ? – OO7 Mar 10 '15 at 10:35
  • you can see a sample code on my post. I want to direct print it (the display format would be PDF for example). Basically it would be a PDF output that would be printed without previewing it on screen. – user1260928 Mar 10 '15 at 10:48
  • See my answer. I hope it solves ur problem. – OO7 Mar 10 '15 at 10:57

1 Answers1

3

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

Community
  • 1
  • 1
OO7
  • 2,785
  • 1
  • 21
  • 33
  • Thanks! seems like I ll have to embed javascript in my PDF with Jasper. That should work fine. My ultimate goal is to silent print this pdf, but after a few hours of search, it seems that it's impossible. – user1260928 Mar 10 '15 at 14:55
  • Welcome. Good to know your problem has been solved with this. – OO7 Mar 11 '15 at 06:47