Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void imprimir(String datos) {
- try {
- datos = reemplazarCaracteresEspeciales(datos);
- // char[] cortePapel = new char[]{0x1d, 0x56, 0x41,0x10};
- char[] cortePapel = new char[]{0x1d, 'V', 1};
- char[] cortePapel2 = new char[]{29, 'V', 1};
- byte[] open = {27, 112, 48, 55, 121};
- // String codi=new String(datos.getBytes());
- System.out.println(datos);
- String ss;
- PrintService service = PrintServiceLookup.lookupDefaultPrintService();
- if(service == null){
- return;
- }
- DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
- DocPrintJob pj = service.createPrintJob();
- if (AbrirGabeta) {
- ss = new String(datos + "\n\n\n\n .") + new String(cortePapel) + new String(open);
- } else {
- ss = new String(datos + "\n\n\n\n .") + new String(cortePapel);
- }
- byte[] bytes;
- bytes = ss.getBytes();
- Doc doc = new SimpleDoc(bytes, flavor, null);
- pj.print(doc, null);
- //realiza el corte de papel
- // String ss2 = new String(cortePapel);
- // byte[] bytes2;
- // bytes2 = ss2.getBytes();
- // Doc doc2 = new SimpleDoc(bytes2, flavor, null);
- // pj.print(doc2, null);
- } catch (Exception e) {
- e.printStackTrace();
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement