[英]Unable to print Turkish characters from Xamarin.Forms application to Zebra mobile printer using CPCL
I am trying to print from a Xamarin.Forms application to Zebra ZQ220 mobile printer over bluetooth.我正在尝试通过蓝牙从 Xamarin.Forms 应用程序打印到 Zebra ZQ220 移动打印机。
I installed Zebra.Printer.SDK version 2.15.2634 and i am able to print.我安装了 Zebra.Printer.SDK 版本 2.15.2634,我可以打印了。
For Turkish character printing, i stored the font file SWISS721 in Zebra printer, and i am able to print Turkish characters via Zebra Setup Utilities / Open Communication With Printer / Direct Communication using my CPCL code, which is below.对于土耳其语字符打印,我将字体文件 SWISS721 存储在 Zebra 打印机中,并且我能够通过 Zebra Setup Utilities / Open Communication With Printer / Direct Communication 使用我的 CPCL 代码打印土耳其语字符,如下所示。
! 0 200 200 500 1
PCX 0 1 !<NRPLOGO.PCX
T SWF12.CPF 0 125 180 şŞ iİ üÜ ğĞ öÖ çÇ
T SWF08.CPF 0 1 225 Tarih : 01.01.2022 Makbuz No : NTQ4NzIzNTM=
PRINT
In Xamarin.Forms application, according to Zebra documentation, i created a string to store CPCL like below:在 Xamarin.Forms 应用程序中,根据 Zebra 文档,我创建了一个字符串来存储 CPCL,如下所示:
private const string RealTestLabelCpclSwiss = "! 0 200 200 500 1\r\n"
+ "PCX 0 1 !<NRPLOGO.PCX\r\n"
+ "T SWF12.CPF 0 125 180 şŞ iİ üÜ ğĞ öÖ çÇ\r\n"
+ "T SWF08.CPF 0 1 225 Tarih : 01.01.2022 Makbuz No : NTQ4NzIzNTM=\r\n"
+ "PRINT\r\n";
To send this string to printer, this needs to be converted to a byte array, and Zebra documentation uses UTF8 encoding like below:要将此字符串发送到打印机,需要将其转换为字节数组,Zebra 文档使用 UTF8 编码,如下所示:
return Encoding.UTF8.GetBytes(RealTestLabelCpclSwiss);
I can print to printer but Turkish characters like şŞ İ Ğ are not printed correctly.我可以打印到打印机,但土耳其语字符如 şŞ İ Ğ 打印不正确。
I assume this is an encoding issue, and i need to use maybe a different encoding, tried the encodings below:我认为这是一个编码问题,我可能需要使用不同的编码,尝试了以下编码:
return Encoding.Default.GetBytes(RealTestLabelCpclSwiss);
return Encoding.ASCII.GetBytes(RealTestLabelCpclSwiss);
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
return Encoding.GetEncoding(1254).GetBytes(RealTestLabelCpclSwiss);
return Encoding.GetEncoding("ISO-8859-9").GetBytes(RealTestLabelCpclSwiss);
But still i can't print Turkish characters with Xamarin.Forms.但我仍然无法使用 Xamarin.Forms 打印土耳其语字符。
My test device is an iPhone and i also checked the west checkbox in iOS project properties / iOS Build / Internationalization.我的测试设备是 iPhone,我还在 iOS 项目属性/iOS 构建/国际化中选中了 west 复选框。
How can i correct this encoding issue with Xamarin.Forms?如何使用 Xamarin.Forms 纠正此编码问题?
I resolved the issue.我解决了这个问题。 I used
我用了
Encoding.GetEncoding("iso-8859-9")
instead of代替
Encoding.GetEncoding("ISO-8859-9")
and i am able to print Turkish characters.而且我能够打印土耳其语字符。
I didn't know this encoding name is case sensitive.我不知道这个编码名称区分大小写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.