I am building an app that prints out a receipt using a bluetooth thermal printer.I am able to connect and print using the printer but I can't figure what all these ESC/POS commands mean.
The printer prints my text white on a black background and I actually want the text to be black and background white. I am not sure how to achieve this type of formatting using the ESC/POS commands.
Here is my printing code:
if (btsocket == null) {
Intent BTIntent = new Intent(getApplicationContext(), DeviceList.class);
this.startActivityForResult(BTIntent, DeviceList.REQUEST_CONNECT_BT);
} else {
OutputStream opstream = null;
try {
opstream = btsocket.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
outputStream = opstream;
//print command
try {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
outputStream = btsocket.getOutputStream();
byte[] format = { 27, 33, 0 };
byte[] printformat = {0x1B, 0 * 21, FONT_TYPE};
outputStream.write(format);
//print title
printUnicode();
//print normal text
outputStream.write(format);
printCustom(message, 0, 0);
//printPhoto(R.drawable.img);
printNewLine();
outputStream.write(format);
printText(" >>>> Thank you <<<< "); // total 32 char in a single line
//resetPrint(); //reset printer
//printUnicode();
printNewLine();
printNewLine();
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
The first line printUnicode();
actually prints just fine, black characters on a white background, but the rest of the paper gets printed on black background with white characters. Is there a document out there explaining all the ESC/POS commands?
printUnicode
may actually write a BOM character U+FEFF whose bytes may constitute a white-on-black control command; comment it out. – Joop Eggen