anastaciocintra / escpos-coffee

Java library for ESC/POS printer
https://anastaciocintra.github.io/escpos-coffee
MIT License
277 stars 72 forks source link

'0' Printing at the beginning of the line #55

Closed immdav closed 3 years ago

immdav commented 3 years ago

When printing using using writeLF(), '0' shows only at the beginning of the line and using write() it adds '0' at the start and end of the line. Any idea how to fix this?

image

When trying to System out it shows this

image

anastaciocintra commented 3 years ago

hi @wellnotanaccount can you share your peace of code to reproduce this problem?

immdav commented 3 years ago

Hello @anastaciocintra, I'm using the sample code.


        PrintService printService = PrinterOutputStream.getPrintServiceByName("58 Printer");
        PrinterOutputStream printerOutputStream = new PrinterOutputStream(printService);
        EscPos escpos = new EscPos(printerOutputStream);

        escpos.writeLF("Test Test Test Test Test");
        escpos.write("Test Test Test Test Test");

        escpos.feed(5);
        escpos.cut(EscPos.CutMode.FULL);
        escpos.close();

        EscPos escpos1 = new EscPos(System.out);
        escpos1.writeLF("Test Test Test Test Test");
        escpos1.feed(5);
        escpos1.cut(EscPos.CutMode.FULL);
        escpos1.close();
anastaciocintra commented 3 years ago

It is printing well in mine printer (epson tm-t20)

20201112_083015

maybe your printer doesn't have text style capabilities. You can try another way to style the text.

        PrintService printService = PrinterOutputStream.getPrintServiceByName("tm-t20-usb" );
        PrinterOutputStream printerOutputStream = new PrinterOutputStream(printService);
        EscPos escpos = new EscPos(printerOutputStream);

//        escpos.writeLF("Test Test Test Test Test");
//        escpos.write("Test Test Test Test Test");

        PrintModeStyle normal = new PrintModeStyle();
        escpos.writeLF(normal,"hello normal PrintModeStyle");
        PrintModeStyle rightBold = new PrintModeStyle().setBold(true).setJustification(EscPosConst.Justification.Right);
        escpos.writeLF(rightBold,"Right bold");
        escpos.feed(5).cut(EscPos.CutMode.FULL);
        escpos.close();

more on https://github.com/anastaciocintra/escpos-coffee/wiki/Text-Styles

I hope that it will work. see you

immdav commented 3 years ago

weird.. I ran the code you gave.. Normal Style works but not on the 2nd line(Right Bold) I tried to style both lines with normal but 2nd line still shows '0' on the last next line.

 escpos.writeLF(normal,"hello normal PrintModeStyle");
 escpos.writeLF(normal,"Right bold"); 

image

image

I'm using Rongta RP58, the printer self-test shows normal. Not sure what is causing the '0'.

I will try to experiment with styling, see if this will fix my issue. I'll update here.

Thank you!

anastaciocintra commented 3 years ago

weird.. I ran the code you gave.. Normal Style works but not on the 2nd line(Right Bold) I tried to style both lines with normal but 2nd line still shows '0' on the last next line.

I'm thinking here: it is one possible that your printer is printing zero when you send one cut, it is because on cut(), the driver send ascii 48 '0' and the printer doen't recognize the cut command (GS V command).

thest the code without cut...

        PrintService printService = PrinterOutputStream.getPrintServiceByName("tm-t20-usb" );
        PrinterOutputStream printerOutputStream = new PrinterOutputStream(printService);
        EscPos escpos = new EscPos(printerOutputStream);

//        escpos.writeLF("Test Test Test Test Test");
//        escpos.write("Test Test Test Test Test");

        PrintModeStyle normal = new PrintModeStyle();
        escpos.writeLF(normal,"hello normal PrintModeStyle");
        PrintModeStyle rightBold = new PrintModeStyle().setBold(true).setJustification(EscPosConst.Justification.Right);
        escpos.writeLF(rightBold,"Right bold");
        // change this line
//        escpos.feed(5).cut(EscPos.CutMode.FULL);
        // by this
        escpos.feed(15);
        escpos.close();
immdav commented 3 years ago

image

even feed(15); also gives me zero but I was able to fix it by using escape escpos.writeLF(normal,"\n\n\n"); instead.

image

PrintModeStyles works perfectly! Thank you very much @anastaciocintra!

anastaciocintra commented 3 years ago

good @wellnotanaccount count on me. if you discover wich sequence is the cut on your printer send here.