【发布时间】:2019-10-27 22:11:18
【问题描述】:
我正在构建一个使用蓝牙热敏打印机打印收据的应用程序。我能够使用打印机连接和打印,但我无法弄清楚所有这些 ESC/POS 命令的含义。
打印机在黑色背景上打印我的白色文本,我实际上希望文本是黑色和白色背景。我不知道如何使用 ESC/POS 命令实现这种格式。
这是我的打印代码:
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();
}
}
第一行printUnicode(); 实际上可以很好地打印白色背景上的黑色字符,但纸张的其余部分会打印在带有白色字符的黑色背景上。那里有解释所有 ESC/POS 命令的文档吗?
【问题讨论】:
-
对你的API没有经验,但是
printUnicode实际上可能会写一个BOM字符U+FEFF,它的字节可能构成一个黑白控制命令;把它注释掉。 -
打印机语言应记录在打印机最初随附的打印机手册中。否则,它可能可以从制造商处在线获得。然后,您可以查找打印机语言的文档。
标签: java android printing escpos