I am using JasperReports 1.3.1 to print the report. I am sing eclipse and tomcat for development purpose.
In eclipse, when i run the application, the below code will show the listed printer devices and print button. If i click the print button, the report is printing by selected device.
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(MediaSizeName.ISO_A5);
PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
exporter.exportReport();
Here I am passing jasperPrint as a parameter which i manually construted.Its working good
My problem is:
I created war file and pasted in tomcat Apache Software Foundation\Tomcat 6.0\webapps
directory and started the tomcat by using services.msc.
At this point, its not displaying the listed printer details and also not printing.
I put some logger, I found that, the code is hanging with exporter.exportReport();
after this line code is not executing .
Please suggest me for how to print from client side using jasper
Looks like a access right problem to me.
Is the printer a network printer? Then make sure that your Tomcat-Service has access rights to the network. If you start Tomcat as a windows service, Tomcat runs per default as "local system user" and have no rights to access network. This would explain that no printer is listed and you can't print. Eclipse is started by you, so the eclipse-process have your rights and can access the network and the printer.
To change the Tomcat-Service user, go to Windows Services --> Right click on Tomcat Service --> Properties --> Login --> This Account --> Type name/pass from a user that have the right to access the printer over the network (maybe you :) ).
Hope it helps, even if the question is some month ago.