首页 > 解决方案 > 无法打印国际字符

问题描述

我正在使用 node-thermal-printer 节点模块来打印一些越南文字。我打印了“Thành phố Hồ Chí Minh”来测试它。但它打印“?” 在几个地方,如附图所示。任何帮助将不胜感激来解决这个问题。我还使用了文档中提到的WPC1258_VIETNAMESE等不同的字符集,但情况仍然相同。我正在使用以下节点模块https://github.com/Klemen1337/node-thermal-printer

在此处输入图像描述

标签: javascriptnode.jsthermal-printer

解决方案


我使用缓冲区数据而不是原始文本进行了测试,它似乎工作正常。但我没有用真正的打印机测试过。

在代码段下方运行,我的输出将如下所示:

Thành phố Hồ Chí Minh
------------------------------------------------
const ThermalPrinter = require("node-thermal-printer").printer;
const PrinterTypes = require("node-thermal-printer").types;

(async () => {
  let printer = new ThermalPrinter({
    type: PrinterTypes.STAR,
    interface: 'tcp://xxx.xxx.xxx.xxx',
    characterSet: 'SLOVENIA',
    removeSpecialCharacters: false,
    lineCharacter: "-",
    options: {
      timeout: 1000
    }
  });

  printer.setBuffer(Buffer.from("Thành phố Hồ Chí Minh\n"));
  printer.drawLine();

  console.log(printer.getText());

  // I do not have any real printer
  // try {
  //   await printer.execute();
  //   console.log("Print success.");
  // } catch (error) {
  //   console.error("Print error:", error);
  // }
})();

推荐阅读