Search code examples
javaepsonescpos

Text size Epson TM-H5000II


I'm trying to reduce the size of the text, according to the manual i need to use the ESC ! 1 (https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=23) but i dont know how to pass it to java code, i try define a bite and use decimal, hex and ASCII but doesnt work.

public class JavaPrinter implements PrinterApi {
private Logger logger = LogManager.getLogger(JavaPrinter.class);

PrintService printService;
boolean isFile = false;
String printerName = null;
PrintStream prnStr;
private PipedInputStream pipe;
PipedOutputStream dataOutput;
Doc mydoc;

byte[] widthNormal = { 0x1b, '!', '1' };
@Override
public void setNormal() {
    if (isFile)
        return;
    try {
        prnStr.write(widthNormal);
    } catch (IOException e) {
        throw new DeviceServerRuntimeException("", e);
    }
}

Above is part of the code i write, i appreciate any advice, help! THX


Solution

  • You need to use 1 as a number with the ESC ! command to change from the larger Font A to the smaller Font B in ESC/POS.

    You also need to follow it with some text and a newline, which I can't see in your example. A self-contained Java example would look like this:

    import java.io.FileOutputStream;
    import java.io.IOException;
    
    class FontChangeDemo {
        public static void main(String[] argv) throws IOException {
            byte[] reset = {0x1b, '@'};
            byte[] fontA = {0x1b, '!', 0x00};
            byte[] fontB = {0x1b, '!', 0x01};
    
            try(FileOutputStream outp = new FileOutputStream("/dev/usb/lp0")) {
                outp.write(reset);
                outp.write("Font A\n".getBytes());
                outp.write(fontB);
                outp.write("Font B\n".getBytes());
                outp.write(fontA);
                outp.write("Font A again\n".getBytes());
            }
        }
    }
    

    Which displays this on a TM-T20II:

    Example output

    This assumes that your setup is otherwise functioning, and is capable of shipping binary data to your printer.