2016-07-29 2 views
0

У меня проблема на моем принтере Job .. Я установил свой сценарий и задал размер бумаги, но принтер всегда прокручивается после окончания печати. ​​ i use epson LX -300 + II в моих Epson LX-300, LX-310 и LX-800, печать выполняется нормально и автоматическая остановка принтера при завершении печати, но в моем epson LX-300 + II принтер всегда прокручивается после окончания печати. я не знаю, почему, и я использую тот же сценарий для печати .. здесь мой сценарий для размера набора пользовательских бумаги:как остановить печать после завершения работы на принтере java

public void setPrinter(String textParam, String spesialWords, int gotoX2) { 

    try { 
     String destination = ""; 
     boolean printToDoc = true; 
     PrinterJob pj = PrinterJob.getPrinterJob(); 
     //boolean printDialog = pj.printDialog(); 
     System.out.println("--------------------"); 

     //PageFormat pf = pj.getPageFormat(null); 
     PageFormat pf = pj.defaultPage(); 
     Paper paper = pf.getPaper(); 

     double cm = 72.0/2.54; 
     if (!destination.equalsIgnoreCase("document.pdf")) { 
      if (destination.equalsIgnoreCase("printer")) { 
       paper.setSize(26 * cm, 7 * cm); 
      } 
     } 
       paper.setSize(23 * cm, 7 * cm); 
     double getHeight = 7 * cm; 
     double getWidth = 23 * cm; 
     double margin = 0.0; // half inch 

     paper.setImageableArea(margin, margin, paper.getWidth(), paper.getHeight()); 
     pf.setPaper(paper); 
     System.out.println("=========================================="); 
     System.out.println("paper height : "+getHeight); 
     System.out.println("paper width : "+getWidth); 

     PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet(); 
     if (destination.equalsIgnoreCase("document.pdf")) { 
      PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService(); 
      DocPrintJob printerJob = defaultPrintService.createPrintJob(); 
      File pdfFile = new File(destination); 
      SimpleDoc simpleDoc = new SimpleDoc(pdfFile.toURL(), DocFlavor.URL.AUTOSENSE, null); 
      try { 
       printerJob.print(simpleDoc, null); 
      } catch (PrintException ex) { 
       Logger.getLogger(Printing2.class.getName()).log(Level.SEVERE, null, ex); 
      } 

     } else if (destination.equalsIgnoreCase("document.ps")) { 
      try { 
       if (textParam.toLowerCase().contains("post")) { 
        destination = "post_"+destination; 
       } else if (textParam.toLowerCase().contains("non")) { 
        destination = "non_"+destination; 
       } else if (textParam.toLowerCase().contains("token")) { 
        destination = "pre_"+destination; 
       } 

       attr_set.add(new Destination(new java.net.URI("file:" + destination))); 
      } catch (URISyntaxException ex) { 
       Logger.getLogger(Printing2.class.getName()).log(Level.SEVERE, null, ex); 
      } 
     } 
     PrinterResolution pr = new PrinterResolution(120, 144, PrinterResolution.DPI); 
     attr_set.add(pr); 

     pj.setPrintable(new MyPrintable(textParam, spesialWords, gotoX2), pf); 
     if (!destination.equalsIgnoreCase("document.pdf")) { 

      try { 
       //System.out.println("ini print"); 
       if (destination.equalsIgnoreCase("xps")) { 
        pj.print(); 
       } else { 
        pj.print(attr_set); 
       } 
      } catch (PrinterException e) { 
       System.out.println(e); 
       javax.swing.JOptionPane.showMessageDialog(rootPane, "Gagal mencetak struk, Silahkan lihat pengaturan printer anda"); 
      } 
     } 

    } catch (IOException ex) { 
     //System.out.println("testing cuuy"); 
     Logger.getLogger(Printing2.class.getName()).log(Level.SEVERE, null, ex); 
    } 

} 

ответ

0

я решить мою проблему с: изменить мой принтер водителя LX- 300 + II до lx-800 Я не знаю почему. , но он отлично работает

Смежные вопросы