我可以打印文本、阿拉伯字符,但我无法打印格式化文本,如居中对齐、粗体文本等
我正在使用这个插件来打印数据https://github.com/don/BluetoothSerial
以下是对齐中心和粗体文本的命令。
TXT_ALIGN_CT: '\x1b\x61\x01', // Centering
TXT_BOLD_ON: '\x1b\x45\x01';
遵循以下步骤: 1.使用以下函数将字符串转换为字节
private getPrintData(TEXT: string) {
// based on http://ciaranj.blogspot.fr/2007/11/utf8-characters-encoding-in-javascript.html
var bytes = [];
for (var n = 0; n < TEXT.length; n++) {
var c = TEXT.charCodeAt(n);
if (c < 128) {
bytes[bytes.length] = c;
} else if ((c > 127) && (c < 2048)) {
bytes[bytes.length] = (c >> 6) | 192;
bytes[bytes.length] = (c & 63) | 128;
} else {
bytes[bytes.length] = (c >> 12) | 224;
bytes[bytes.length] = ((c >> 6) & 63) | 128;
bytes[bytes.length] = (c & 63) | 128;
}
}
return bytes;
}
const printData = this.getPrintData(getPrintData('你好'));
this.printer.printData(printData ).then((success) => {});
它工作正常。
2. 尝试将 ESC/POS 命令作为十六进制代码传递,如下所示。
const data = new Uint8Array([0x2fa00bf0e86c440658a6a71]);
this.printer.printData(data);
它不显示粗体文本,
谁能帮帮我吗 ??