0 Replies Latest reply: Oct 7, 2011 7:34 AM by 893102 RSS

    Print in duplex problem

    893102
      Hi,
      i've a problem with printservice API in java 1.6
      i'would print a PDF file with PrintService but when i want print with attributs Sides.DUPLEX, my printer doesn't print with my settings.

      Code example :
      PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
                     //pras.add(MediaSizeName.ISO_A4);
                     pras.add(Sides.DUPLEX);
                     DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;


                     // list printers flavor supported
                     PrintService service = null;
                     PrintService printService[] = PrintServiceLookup
                               .lookupPrintServices(null, pras);


                     // choice printer
                     for (int i = 0; i < printService.length; i++) {
                          PrintService printer = printService;
                          System.out.println("Name printer:" + printer.getName());
                          System.out.println("Name choice :" + namePrinter);
                          /*DocFlavor[] docFalvor = printer.getSupportedDocFlavors();
                for (int i2 = 0; i2 < docFalvor.length; i2++) {
                System.out.println(docFalvor[i2].getMimeType());
                }*/
                
                          if (printer.getName().equalsIgnoreCase(namePrinter)) {
                               service = printer;
                               break;
                          }
                     }

                     if (service != null) {
                          DocPrintJob job = service.createPrintJob();
                          // Monitor print job events
                          PrintJobWatcher pjDone = new PrintJobWatcher(job);
                          try {


                               DocAttributeSet das = new HashDocAttributeSet();
                               das.add(Sides.DUPLEX);
                               Doc doc = new SimpleDoc(flux, flavor, das);
                               job.print(doc, pras);

      //my printer doesn't print in DUPLEX mode




                          } catch (PrintException ex) {
                               System.out.println("ERREUR : impression");
                               ex.printStackTrace();
                          }
                          // Wait for the print job to be done
                          pjDone.waitForDone();
                     } else {
                          System.out.println("Aucune imprimante trouvée !!");
                     }