使用cordova打印到包含来自ios的阿拉伯语文本的zpl内容的imz320

时间:2017-03-07 06:30:36

标签: javascript ios cordova platform zpl

我正在使用cordova开发混合应用程序。我能够在Android版本中打印阿拉伯语文本的zpl内容。但是相同的zpl代码在ios版本中不起作用。打印机获取信号,蓝灯闪烁。当内容有阿拉伯语文本时,不要打印。

我正在使用Zebra iMZ320打印机。你能否分享一个同样的工作实例,为ios提供阿拉伯语内容。

var TestPrint = "^XA^FO50,50^A@E:TT0003M_.TTF,N,50,50^FD"+"الفئة الرابعة عشر"+"^FS ^XZ";
//-- "ÙحاÙÙØ©"
localStorage.iosConnected_ZebraPrinter_Name = 'XXXXJ142401535';
window.plugins.CordovaPrinter.print(
    function (success) { // Call the print method
        console.log('Platform : ios, Successfully printed...'
                   + '\n thru. ',localStorage.iosConnected_ZebraPrinter_Name);
        },
    function error(err) {
        console.log('Error Printing to ' + localStorage.iosConnected_ZebraPrinter_Name);
        console.log(err);
    },
    localStorage.iosConnected_ZebraPrinter_Name, //serialArray[0],
    TestPrint);

1 个答案:

答案 0 :(得分:0)

经过一个多月的挣扎,终于找到了解决问题的方法如下:



//-ARABIC TEXT ENCODING - FOR IOS---------------------------
/*-----String to utf-8 encoded hex-----*/
function toHex(str,hex){
  try{
    //We have appended '-', because, you need to prefix the utf-8 hex code with an underscore, to be printed in ZPL
    hex = '_' + unescape(encodeURIComponent(str))
    .split('').map(function(v){
      return v.charCodeAt(0).toString(16)
    }).join('_')
  }
  catch(e){
    hex = str
    console.log('invalid text input: ' + str)
  }
  return hex
}
//-EXAMPLE : console.log('toHex of ' + str + ' is : ' + toHex(str, 16));

//----------------------------------------------------------
var TestPrint = "^XA" +
"^LH100,150" +
"^CWT,E:TT0003M_.FNT" +
"^CFT,30,30" +
"^CI28" +
"^FT0,0^FH^FDTesting 1 2 3...^FS" + 
"^FT0,50^FH^FD" +toHex(str, 16)+ "^FS" +
"^FT0,100^B3^FDAAA001^FS" +
"^XZ" ;
console.log('TestPrint : ', TestPrint);

localStorage.iosConnected_ZebraPrinter_Name = 'XXXXJ142401535';
window.plugins.CordovaPrinter.print(
    function (success) { // Call the print method
        console.log('Platform : ios, Successfully printed...'
                   + '\n thru.', localStorage.iosConnected_ZebraPrinter_Name);
        },
    function error(err) {
        console.log('Error Printing to ' + localStorage.iosConnected_ZebraPrinter_Name);
        console.log(err);
    },
    localStorage.iosConnected_ZebraPrinter_Name, //serialArray[0],
    TestPrint);