我也遇到了同样的问题,我找到了并解决了它。
我共享韩语编码代码。
朝鲜语编码代码:
cp949
和
println
到
text
这个包默认字体太大,
所以你需要控制字体大小
.size(0.01, 0.01) // default .size(1,1)
添加此代码:
const options = { encoding: 'cp949' }
完整代码:
const escpos = require('escpos');
escpos.SerialPort = require('escpos-serialport');
module.exports = {
printSerial: function(port, data){
let device = new escpos.SerialPort('COM2', { baudRate: 19200 });
const options = { encoding: 'cp949' } // <- Add This option.
let printer = new escpos.Printer(device, options);
device.open(function(err){
printer
.size(0.01, 0.01) // <-- Font size small
.font('A')
.encode('CP949')
.align('CT')
.style('NORMAL')
.text('Receipt') // <- `println` to `text`
.newLine()
.align('LT')
.style('NORMAL')
.tableCustom([
{ text: 'Date:', width: 0.2 },
{ text: '2021-01-04 11:11', width: 0.6 }
])
.style('NORMAL')
.tableCustom([
{ text: 'Order ID:', width: 0.2 },
{ text: '050-7866-2406', width: 0.6 }
])
.style('NORMAL')
.tableCustom([
{ text: 'ì íë²í¸:', width: 0.2 },
{ text: '200000000', width: 0.6, align: 'LEFT' }
], { encoding: 'EUC-KR' })
.tableCustom([
{ text: 'ë©ëª¨:', width: 0.4 },
{ text: '문ìì ëê³ ë²¨ì ëë¬ì£¼ì¸ì', width: 0.6 }
], 'CP949')
.drawLine()
.newLine()
.tableCustom([
{ text: '기ì¬ë ì´ë¦:', width: 0.4 },
{ text: '기ì¬ì´ë¦', width: 0.6 }
], 'CP949')
.tableCustom([
{ text: '기ì¬ë ë²í¸:', width: 0.4 },
{ text: '010-1234-5678', width: 0.6 }
], 'CP949')
.drawLine()
.newLine()
.tableCustom([
{ text: 'ë´ë¶ê·', width: 0.33, align: 'LEFT' },
{ text: 'ë´ë¶', width: 0.33, align: 'CENTER' },
{ text: 'ì¨ê³¼', width: 0.33, align: 'CENTER' }
], 'CP949')
.tableCustom([
{ text: 'ë´ë¶ê·ì¨ê³¼', width: 0.33, align: 'LEFT' },
{ text: '1', width: 0.33, align: 'CENTER' },
{ text: '2,000,000 ì', width: 0.33, align: 'CENTER' }
], 'CP949')
.drawLine()
.newLine()
.tableCustom([
{ text: 'í©ê³', width: 0.6, align: 'LEFT' },
{ text: '2,000,000 ì', width: 0.4, align: 'RIGHT' }
], 'CP949')
.tableCustom([
{ text: 'ë°°ì¡ë£(11.2km)', width: 0.6, align: 'LEFT' },
{ text: '2,000 ì', width: 0.4, align: 'RIGHT' }
], 'CP949')
.tableCustom([
{ text: 'ììë£', width: 0.6, align: 'LEFT' },
{ text: '-0 ì', width: 0.4, align: 'RIGHT' }
], 'CP949')
.drawLine()
.newLine()
.tableCustom([
{ text: 'ì´ê¸ì¡', width: 0.6, align: 'LEFT' },
{ text: '2,000,000 ì', width: 0.4, align: 'RIGHT' }
], 'CP949')
.newLine()
.newLine()
.newLine()
.cut();
setTimeout(function(){
printer.close();
}, 1000);
});
}
};
我希望这对你有帮助。