Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print Chinese Garbled! #57

Closed
qjdice opened this issue Apr 19, 2018 · 4 comments
Closed

Print Chinese Garbled! #57

qjdice opened this issue Apr 19, 2018 · 4 comments

Comments

@qjdice
Copy link

qjdice commented Apr 19, 2018

I want to print chinese but print out the Garbled.
English Is OK.

this is my code:

var printers = require("node-thermal-printer");
printers.init({
type: 'epson',
interface: 'printer:' + printer.getPrinters()[0].name,
characterSet:'CHINA'
});
printers.alignCenter();
printers.println(iconv.encode('--------测试打印----------','GBK'));
printers.println(iconv.encode('--------测试打印----------','UTF-8'));
printers.println('--------测试打印----------');
printers.println('hello');

printers.execute( function(err){
console.dir(err);
});

@alanzhaonys
Copy link

Hi, your printer needs to support Chinese character.

@jevy-wangfei
Copy link

I want to print chinese but print out the Garbled.
English Is OK.

this is my code:

var printers = require("node-thermal-printer");
printers.init({
type: 'epson',
interface: 'printer:' + printer.getPrinters()[0].name,
characterSet:'CHINA'
});
printers.alignCenter();
printers.println(iconv.encode('--------测试打印----------','GBK'));
printers.println(iconv.encode('--------测试打印----------','UTF-8'));
printers.println('--------测试打印----------');
printers.println('hello');

printers.execute( function(err){
console.dir(err);
});

Hi,

Did you resolve the problem? I have the same problem, and I pretty sure that my printer char code setting is Chinese(BIG5).

Yours' Jevy Wang

@qjdice
Copy link
Author

qjdice commented Oct 16, 2018

I want to print chinese but print out the Garbled.
English Is OK.
this is my code:
var printers = require("node-thermal-printer");
printers.init({
type: 'epson',
interface: 'printer:' + printer.getPrinters()[0].name,
characterSet:'CHINA'
});
printers.alignCenter();
printers.println(iconv.encode('--------测试打印----------','GBK'));
printers.println(iconv.encode('--------测试打印----------','UTF-8'));
printers.println('--------测试打印----------');
printers.println('hello');
printers.execute( function(err){
console.dir(err);
});

Hi,

Did you resolve the problem? I have the same problem, and I pretty sure that my printer char code setting is Chinese(BIG5).

Yours' Jevy Wang

I modified the source code need a iconv-lite module
add code to node-thermal-printer/lib/core.js

   var fs = require('fs'),
    net = require("net"),
    PNG = require('pngjs').PNG,
    star = require('./star'),
    epson = require('./epson'),
    getInterface = require("../interfaces"),
    iconv = require('iconv-lite');

and println:function(){}

  println: function(text,isGbk){
    if(isGbk){
      append(iconv.encode(text,'GBK'))
    }else{
      append(text.toString());
    }
    append("\n");
  },

used

 var printer = require("node-thermal-printer");
 printer.init({
		  type: 'epson',
		  interface: printname,
		});
printer.println('测试打印中文',true);

@jevy-wangfei
Copy link

jevy-wangfei commented Oct 21, 2018

I want to print chinese but print out the Garbled.
English Is OK.
this is my code:
var printers = require("node-thermal-printer");
printers.init({
type: 'epson',
interface: 'printer:' + printer.getPrinters()[0].name,
characterSet:'CHINA'
});
printers.alignCenter();
printers.println(iconv.encode('--------测试打印----------','GBK'));
printers.println(iconv.encode('--------测试打印----------','UTF-8'));
printers.println('--------测试打印----------');
printers.println('hello');
printers.execute( function(err){
console.dir(err);
});

Hi,
Did you resolve the problem? I have the same problem, and I pretty sure that my printer char code setting is Chinese(BIG5).
Yours' Jevy Wang

I modified the source code need a iconv-lite module
add code to node-thermal-printer/lib/core.js

   var fs = require('fs'),
    net = require("net"),
    PNG = require('pngjs').PNG,
    star = require('./star'),
    epson = require('./epson'),
    getInterface = require("../interfaces"),
    iconv = require('iconv-lite');

and println:function(){}

  println: function(text,isGbk){
    if(isGbk){
      append(iconv.encode(text,'GBK'))
    }else{
      append(text.toString());
    }
    append("\n");
  },

used

 var printer = require("node-thermal-printer");
 printer.init({
		  type: 'epson',
		  interface: printname,
		});
printer.println('测试打印中文',true);

Hi,
Thank you very much for your replay.

Which printer did you use? I tried on POS-8220, and set the charset to GB18030, and it still print mess code.

I'm wondering it is caused by printer.

Do you have any other idea which could resolve the mess code problem?

Thanks you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants