Advertisement
fabiomoreno

Metodo imprimir impresora tipo POS

Aug 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. public void imprimir(String datos) {
  2.         try {
  3.            
  4.             datos = reemplazarCaracteresEspeciales(datos);
  5. //            char[] cortePapel = new char[]{0x1d, 0x56, 0x41,0x10};
  6.             char[] cortePapel = new char[]{0x1d, 'V', 1};
  7.             char[] cortePapel2 = new char[]{29, 'V', 1};
  8.             byte[] open = {27, 112, 48, 55, 121};
  9. //            String codi=new String(datos.getBytes());
  10.             System.out.println(datos);
  11.             String ss;
  12.             PrintService service = PrintServiceLookup.lookupDefaultPrintService();
  13.             if(service == null){
  14.                 return;
  15.             }
  16.             DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
  17.             DocPrintJob pj = service.createPrintJob();
  18.             if (AbrirGabeta) {
  19.                 ss = new String(datos + "\n\n\n\n .") + new String(cortePapel) + new String(open);
  20.             } else {
  21.                 ss = new String(datos + "\n\n\n\n .") + new String(cortePapel);
  22.             }
  23.             byte[] bytes;
  24.             bytes = ss.getBytes();
  25.             Doc doc = new SimpleDoc(bytes, flavor, null);
  26.             pj.print(doc, null);
  27.  
  28.             //realiza el corte de papel
  29. //            String ss2 =  new String(cortePapel);
  30. //            byte[] bytes2;
  31. //            bytes2 = ss2.getBytes();
  32. //            Doc doc2 = new SimpleDoc(bytes2, flavor, null);
  33. //            pj.print(doc2, null);
  34.         } catch (Exception e) {
  35.             e.printStackTrace();
  36.             JOptionPane.showMessageDialog(null, "<html>No se pudo imprimir.<br>Error en la configuración de la impresora.<br><strong>Error:</strong>" + e, "Error de impresión", JOptionPane.WARNING_MESSAGE);
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement