Topic
2 replies Latest Post - ‏2011-12-12T06:53:41Z by xiaohe9527
SystemAdmin
SystemAdmin
4672 Posts
ACCEPTED ANSWER

Pinned topic Print directly on AS400 (iSeries)

‏2009-06-05T14:48:57Z |
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<services3.length;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.<init>(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.<init>(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...
Updated on 2011-12-12T06:53:41Z at 2011-12-12T06:53:41Z by xiaohe9527
  • SystemAdmin
    SystemAdmin
    4672 Posts
    ACCEPTED ANSWER

    Re: Print directly on AS400 (iSeries)

    ‏2009-06-08T12:21:58Z  in response to SystemAdmin
    I have some more informations, I have add this code to list the flavors tha each printers supports:

    
    PrintService[] allServices = PrintServiceLookup.lookupPrintServices(null, 
    
    null); 
    
    for (PrintService ps : allServices) 
    { System.out.println(ps  
    " supports :"); DocFlavor[] flavors = ps.getSupportedDocFlavors(); 
    
    for (
    
    int i = 0; i < flavors.length; i+</i>) 
    { System.out.println(
    "\t" + flavors[i]); 
    } 
    }
    


    Here is the resuklt for all the printers that do not work :

    
    Printer ISeriesPrintService: PRT01 supports :   application/vnd.ibm.modcap; class=
    "[B"   application/vnd.ibm.modcap; class=
    "java.io.InputStream"   application/vnd.ibm.modcap; class=
    "java.net.URL"   application/vnd.ibm.scs; class=
    "[B"   application/vnd.ibm.scs; class=
    "java.io.InputStream"   application/vnd.ibm.scs; class=
    "java.net.URL"
    


    For the only printer that works :

    
    Printer ISeriesPrintService: PRT02 supports :   application/vnd.ibm.modcap; class=
    "[B"   application/vnd.ibm.modcap; class=
    "java.io.InputStream"   application/vnd.ibm.modcap; class=
    "java.net.URL"   application/vnd.ibm.scs; class=
    "[B"   application/vnd.ibm.scs; class=
    "java.io.InputStream"   application/vnd.ibm.scs; class=
    "java.net.URL"   application/vnd.hp-pcl; class=
    "[B"   application/vnd.hp-pcl; class=
    "java.io.InputStream"   application/vnd.hp-pcl; class=
    "java.net.URL"   application/x-java-jvm-local-objectref; class=
    "java.awt.print.Pageable"   application/x-java-jvm-local-objectref; class=
    "java.awt.print.Printable"
    


    So now my question is, is there a way to add those properties (the lasts ones) to the others printers? If yes, how?

    Thanks
  • xiaohe9527
    xiaohe9527
    1 Post
    ACCEPTED ANSWER

    Re: Print directly on AS400 (iSeries)

    ‏2011-12-12T06:53:41Z  in response to SystemAdmin
    I have the same issue too
    my default printer can print.
    but when it is setting as undefault,It can not print. even if they are the same printer.

    the printer you can print, is it the default printer?
    this problem is very ....