我正在使用 Node 热敏打印机 Node 模块来打印一些越南文本。我打印了 “Thành phố Hồ Chi Minh”来测试一下。但它打印“?”在少数地方,如附图所示。任何帮助解决这个问题将不胜感激。我还使用了不同的字符集,例如文档中提到的 WPC1258_VIETNAMESE,但情况仍然相同。 我正在使用以下 Node 模块 https://github.com/Klemen1337/node-thermal-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);
// }
})();
关于javascript - 无法打印国际字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58333717/