javascript - 无法打印国际字符
问题描述
我正在使用 node-thermal-printer 节点模块来打印一些越南文字。我打印了“Thành phố Hồ Chí Minh”来测试它。但它打印“?” 在几个地方,如附图所示。任何帮助将不胜感激来解决这个问题。我还使用了文档中提到的WPC1258_VIETNAMESE等不同的字符集,但情况仍然相同。我正在使用以下节点模块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);
// }
})();
推荐阅读
- git - 如何解决“在源和目标中重命名”
- html - `grid-auto-rows: 1fr` 没有预期的效果
- javascript - 裁剪背景图像和缩放窗口调整大小
- javascript - 有没有办法在 Vue @click 内联事件中执行原生 JS?
- python - 在 Scala 中创建非法循环引用错误的错误是什么以及为什么是错误?
- python - Reportlab - 表格扩展到多个框架和页面
- django - Django Rest Framework Serializer - 返回相关字段
- asp.net - 文本框值未在 ASP.NET MVC 中更新
- google-sheets-formula - 谷歌表格 SQL 查询
- haskell - 全局变量“total”未正确更新