ESC-POS-.NET icon indicating copy to clipboard operation
ESC-POS-.NET copied to clipboard

How to set the charsetcode? when I try to print chinese,it's show Garbled code

Open alexzm19 opened this issue 3 years ago • 2 comments

alexzm19 avatar Nov 10 '20 02:11 alexzm19

hey @alexzm19 there is not currently a way to print unicode characters, so you need to use a charset that's built in to the printer. Take a look at these issues for more information: #86 #67 . Give it a try and let me know how it goes!

lukevp avatar Nov 11 '20 15:11 lukevp

hey @alexzm19 there is not currently a way to print unicode characters, so you need to use a charset that's built in to the printer. Take a look at these issues for more information: #86 #67 . Give it a try and let me know how it goes!

thank you for answer,I solved the problem step1: In .net core 3.1,.NET Core does not support GB2312 by default step2:Register encodingProvider on startup step3:Change print function return data.ToCharArray().Select(x => (byte)x).ToArray() => return Encoding.GetEncoding("GBK").GetBytes(data)

alexzm19 avatar Dec 15 '20 01:12 alexzm19

Glad we got you solved! @igorocampos this is a common question we get about printing nonstandard character codes. Perhaps we should put something about this in the README?

lukevp avatar Feb 02 '23 15:02 lukevp

Yeah, sounds about right. In addition I do think we could make the Enconding changeable instead of hardcoded UTF-8. See the comment above, Alex had to change the Print method in order to place his own encoding in it. I think we can keep UTF-8 as default, but also let the user change it, if wanted.

I'll see if I can put a PR together about that.

Btw, I'm in the US now :)

igorocampos avatar Feb 09 '23 20:02 igorocampos

@alexzm19 Can you describe with code what step2:Register encodingProvider on startup means? I wish to add this steps in the README.md in details. Thank you

igorocampos avatar Jan 23 '24 03:01 igorocampos

of course Code: Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Link: https://learn.microsoft.com/zh-cn/dotnet/api/system.text.encoding.registerprovider?view=net-6.0

rainonheaert @.***

 

------------------ 原始邮件 ------------------ 发件人: "lukevp/ESC-POS-.NET" @.>; 发送时间: 2024年1月23日(星期二) 中午11:02 @.>; @.@.>; 主题: Re: [lukevp/ESC-POS-.NET] How to set the charsetcode? when I try to print chinese,it's show Garbled code (#88)

@alexzm19 Can you describe with code what step2:Register encodingProvider on startup means? I wish to add this steps in the README.md in details. Thank you

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

alexzm19 avatar Jan 23 '24 03:01 alexzm19

@alexzm19 thanks! I see you replied by email, but I think the link got lost when doing so. When you have the time, if could come back to Github and update your comment adding the URL for the link you mentioned, I'd appreciate it!

igorocampos avatar Jan 23 '24 03:01 igorocampos

Ok, I just updated the comment, thanks for the reminder

rainonheaert @.***

 

------------------ 原始邮件 ------------------ 发件人: "lukevp/ESC-POS-.NET" @.>; 发送时间: 2024年1月23日(星期二) 中午11:21 @.>; @.@.>; 主题: Re: [lukevp/ESC-POS-.NET] How to set the charsetcode? when I try to print chinese,it's show Garbled code (#88)

@alexzm19 thanks! I see you replied by email, but I think the link got lost when doing so. When you have the time, if could come back to Github and update your comment adding the URL for the link you mentioned, I'd appreciate it!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

alexzm19 avatar Jan 23 '24 03:01 alexzm19

Thank you very much! That will do :) Here's some more from the doc: image

igorocampos avatar Jan 23 '24 13:01 igorocampos