我正在使用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);
挣扎了一个多月后,最终找到了解决问题的解决方案,如下所示:
//-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);