4

I'm trying to print on a printer POS for tickets. It's a EPSON TMU220PD. I can print, but I don't know how I can program printer for print with a font bigger and how I can to do for cut the paper automatically. I have reading a lot and there are page where they say I can to use commands ESC/POS but I don't have idea to how work this. I hava a man class with the next code:

   public static void main(String[] args) {
JavaApplication14 java = new JavaApplication14();
try {
    FileWriter file = new FileWriter("/dev/usb/lp2");
    BufferedWriter buffer = new BufferedWriter(file);
    PrintWriter ps = new PrintWriter(buffer);
    java.setFormato(5, ps);
  java.cortar(ps);
}

And method for "cut" is this

 private void cortar(PrintWriter ps) {
try {
    char[] ESC_CUT_PAPER = new char[]{0x1B, 'm'};
    ps.write(ESC_CUT_PAPER);
} catch (Exception e) {
    System.out.print(e);
}

}

When I'm going to print, printer work normally to print text, but It not cut the paper. I need increase the text size too, but I don't know how I can to do It and How I can use commands ESC/POS on java.

Allanh
  • 465
  • 1
  • 7
  • 19

2 Answers2

1

Can you try either

        byte[] bCut = new byte[4];
        bCut[0] = GS;
        bCut[1] = 86;
        bCut[2] = 65;
        bCut[3] = 0;
        String sCut = new String (bCut);
        ps.write(bCut);

or

       char[] cutOff = new char[]
                { 29, 'V', 65, 0 };
        ps.write(cutOff);

and let me know if it works?

Tim
  • 606
  • 1
  • 8
  • 19
0
        String text_to_print = "Hello world!";
        PrintService foundService = PrintServiceLookup.lookupDefaultPrintService();
        DocPrintJob dpj = foundService.createPrintJob();

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        /// your legacy commands ini
        // initialize printer
        outputStream.write(27); // ESC
        outputStream.write('@');

        // print text
        outputStream.write(text_to_print.getBytes());

        // feed 5 lines
        outputStream.write(27); // ESC
        outputStream.write('d');
        outputStream.write(5);

        // cut paper
        outputStream.write(29); // GS
        outputStream.write('V');
        outputStream.write(48);

you can see complete code on here

PapusCoder
  • 101
  • 1
  • 5