Hello
I am using Jasper Report as reporting tool in my web application (using websphere as server).
I try to print directly to a printer that is linked with the server. It
works without any problem if the server is a PC. But if the server is
an AS400 (iSeries V6R0 or V6R1), it does not print.
Here is my code:
PrintService service = null;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.ISO_A4);
//list all printers and select the one selected by the user
PrintService[] services3 = PrintServiceLookup.lookupPrintServices(null, null);
for(int k=0;k
if(services3[k].getName().trim().equals(printer.trim())){
service = services3[k];
}
}
if(service == null){
System.out.println("PRINTER NOT FOUND->"+printer);
}else{
//printing
File file = new File(realBaseDir + "/" + jrxml +".jrprint");
JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(file);
JRExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, service.getAttributes());
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
exporter.exportReport();
}
Here is the exception that is thrown on the AS400 :
5/06/09 11:09:43:186 CEST 000001e5 SystemOut O net.sf.jasperreports.engine.JRException: No suitable print service found.
at net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:152)
at com.project.administrator.jasperreport.JasperReport.execute(JasperReport.java:621)
at com.project.srv.tools.scm.ExecuteJasper.(ExecuteJasper.java:134)
at com.project.batches.scm.OrderConfDocument.doProgram(OrderConfDocument.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at com.project.batches.LaunchJobStateless.Execute(LaunchJobStateless.java:121)
at com.project.batches.LaunchJobStateless.execute(LaunchJobStateless.java:77)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
to solve it, I have added this line in my code (before exporter.exportReport):
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, service);
Now I am getting this exception :
5/06/09 9:57:17:748 CEST 0000009b SystemOut O net.sf.jasperreports.engine.JRException: java.awt.print.PrinterException: Not a 2D print service: ISeriesPrintService: PRT06SIG
at net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:161)
at com.project.administrator.jasperreport.JasperReport.execute(JasperReport.java:582)
at com.project.srv.tools.scm.ExecuteJasper.(ExecuteJasper.java:134)
at com.project.batches.scm.OrderConfDocument.doProgram(OrderConfDocument.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at com.project.batches.LaunchJobStateless.Execute(LaunchJobStateless.java:121)
at com.project.batches.LaunchJobStateless.execute(LaunchJobStateless.java:77)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
Caused by: java.awt.print.PrinterException: Not a 2D print service: ISeriesPrintService: PRT06SIG
at sun.print.RasterPrinterJob.setPrintService(RasterPrinterJob.java:520)
at net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:157)
I have this exception on different AS400 on every printers (something
like 30 printers of all types). I just have 1 printer where it works.
I tried to see what was the difference between this printer and the
other but I was not able to find the difference... It is just a
"simple" laser printer like others in the 30 that are not working...
I have also tried to use this code to print (using PrintServiceAttributeSet instead of the service to give the printer) :
PrintServiceAttributeSet serviceAttributeSet = new HashPrintServiceAttributeSet();
serviceAttributeSet.add(new PrinterName(service.getName(), null));
exporter.setParameter( JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, serviceAttributeSet);
But the result stay the same.
Do anybody have an idea of what the problem could be? Or where I can find some help for this?
Thanks a lot...