Comandos ESC/POS para Impressora termica
06/01/2015
0
Fala galera, então, após pesquisar no Google não achei nada que fosse satisfatório para explicar como funciona (exemplos) a impressão através de comandos ESC/POS no java. se alguém tiver algum material ou exemplos para fornecer.
Fernando Blomer
Curtir tópico
+ 0
Responder
Posts
14/01/2015
Fernando Blomer
Caso alguém tenha interesse achei alguma coisa para começar.
Para enviar para a impressora
public static final char[] START = new char[] { 0x1B, '@' }; public static final char[] CORTAR = new char[] { 0x1B, 'm' }; private static final byte[] CHAR_SIZE_0 = { 0x1B, 0x21, 0x00 }; private static final byte[] CHAR_SIZE_1 = { 0x1B, 0x21, 0x01 }; private static final byte[] CHAR_SIZE_2 = { 0x1B, 0x21, 0x30 }; private static final byte[] CHAR_SIZE_3 = { 0x1B, 0x21, 0x31 }; private static final byte[] AVANCA = { 0x19 }; private static final byte[] POSESQUEDA = { 0x1B, 'j', '0' }; private static final byte[] POSCENTRO = { 0x1B, 'j', '1' }; private static final byte[] POSDIREITA = { 0x1B, 'j', '2' }; private static final byte[] TABHORIZONTAL = { 0x09 }; private static final byte[] startTextCondensado = {0x1B, 0x0F }; private static final byte[] endTextCondensado = { 0x12 }; private static final byte[] startTextExpandido = { 0x1B, 'W', '1' }; private static final byte[] endtTextExpandido = { 0x1B, 'W', '0' }; private static final char[] QRCODE_PREFIX = new char[] { 0x1B, 0x81 }; private static final char[] ESPACOHORIZONTAL = new char[] { 0x20 }; private static final byte[] SET_LINE_SPACING_24 = { 0x1B, 0x33, (byte) 24 }; private static final byte[] SET_LINE_SPACING_30 = { 0x1B, 0x33, (byte) 30 }; private static final byte[] PRINT_AND_FEED_PAPER = { 0x1B, 0x4A, 0x00 }; private static final byte[] REVERSAO = { 0x10, 0x4D, 0x01 };
Para enviar para a impressora
String Ptxt = new String (START)+ new String(CHAR_SIZE_0)+ new String (POSESQUEDA)+ new String(textNegrito("Exemplo de texto em negrito"))+ new String(AVANCA)+ new String(CORTAR); // Impressão DocFlavor df = DocFlavor.INPUT_STREAM.AUTOSENSE; InputStream pis = new ByteArrayInputStream(Ptxt.getBytes()); Doc d = new SimpleDoc(pis, df, null); PrintService P = PrintServiceLookup.lookupDefaultPrintService(); if (P != null) { DocPrintJob job = P.createPrintJob(); try { job.print(d, null); } catch (PrintException e) { e.printStackTrace(); } }
Responder
01/06/2019
Wellington
Caso alguém tenha interesse achei alguma coisa para começar.
Para enviar para a impressora
public static final char[] START = new char[] { 0x1B, '@' }; public static final char[] CORTAR = new char[] { 0x1B, 'm' }; private static final byte[] CHAR_SIZE_0 = { 0x1B, 0x21, 0x00 }; private static final byte[] CHAR_SIZE_1 = { 0x1B, 0x21, 0x01 }; private static final byte[] CHAR_SIZE_2 = { 0x1B, 0x21, 0x30 }; private static final byte[] CHAR_SIZE_3 = { 0x1B, 0x21, 0x31 }; private static final byte[] AVANCA = { 0x19 }; private static final byte[] POSESQUEDA = { 0x1B, 'j', '0' }; private static final byte[] POSCENTRO = { 0x1B, 'j', '1' }; private static final byte[] POSDIREITA = { 0x1B, 'j', '2' }; private static final byte[] TABHORIZONTAL = { 0x09 }; private static final byte[] startTextCondensado = {0x1B, 0x0F }; private static final byte[] endTextCondensado = { 0x12 }; private static final byte[] startTextExpandido = { 0x1B, 'W', '1' }; private static final byte[] endtTextExpandido = { 0x1B, 'W', '0' }; private static final char[] QRCODE_PREFIX = new char[] { 0x1B, 0x81 }; private static final char[] ESPACOHORIZONTAL = new char[] { 0x20 }; private static final byte[] SET_LINE_SPACING_24 = { 0x1B, 0x33, (byte) 24 }; private static final byte[] SET_LINE_SPACING_30 = { 0x1B, 0x33, (byte) 30 }; private static final byte[] PRINT_AND_FEED_PAPER = { 0x1B, 0x4A, 0x00 }; private static final byte[] REVERSAO = { 0x10, 0x4D, 0x01 };
Para enviar para a impressora
String Ptxt = new String (START)+ new String(CHAR_SIZE_0)+ new String (POSESQUEDA)+ new String(textNegrito("Exemplo de texto em negrito"))+ new String(AVANCA)+ new String(CORTAR); // Impressão DocFlavor df = DocFlavor.INPUT_STREAM.AUTOSENSE; InputStream pis = new ByteArrayInputStream(Ptxt.getBytes()); Doc d = new SimpleDoc(pis, df, null); PrintService P = PrintServiceLookup.lookupDefaultPrintService(); if (P != null) { DocPrintJob job = P.createPrintJob(); try { job.print(d, null); } catch (PrintException e) { e.printStackTrace(); } }
Isso vai me ajudar vlw preciso criar uma extensão para o app inventor com esse material pode me ajudar
https://appinventordaniel.jimdo.com/esc-pos-simple-converter/ parecida com essa
Responder
Clique aqui para fazer login e interagir na Comunidade :)