-1

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

  • Your code is not a minimal working example of the problem you are describing, which is that formatting is not being applied to text (downvote was not from me, but is justified). – mike42 Jun 20 '18 at 10:07

1 Answers1

0

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.

mike42
  • 1,608
  • 14
  • 24
  • Ty for your answer, why is the /n important? I try with your code, and some other code that i found in other question, and doesn't work without the /n – Patricio Mora Jun 20 '18 at 16:24