0

我可以打印文本、阿拉伯字符,但我无法打印格式化文本,如居中对齐、粗体文本等

我正在使用这个插件来打印数据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);

它不显示粗体文本,

谁能帮帮我吗 ??

4

1 回答 1

1

一些打印机不支持我们必须使用本机 sdks 来解决的 ESC/POS 命令,我通过创建自定义 cordova 插件来解决

于 2019-06-20T12:54:24.593 回答