lukevp / ESC-POS-.NET

Efficient, Easy to Use Thermal Printing & POS (Windows/Linux/OSX, WiFi/BT/USB/Ethernet)
MIT License
522 stars 171 forks source link

Korean characters are being printed when Arabic CodePages are specified #168

Open lerasah opened 2 years ago

lerasah commented 2 years ago

Printer: Yujin Thermal Printer Windows

Tests done: Printed arabic using Notepad / wordpad/ msword, prints perfect. Printed Arabic characters without codepage, prints question marks.

Thanks.

Code:

          var e = new EPSON();
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            Encoding enc = Encoding.GetEncoding(1256);

            var bytes = ByteSplicer.Combine(
                    e.CodePage(CodePage.WPC1256_ARABIC),
                    e.CenterAlign(),
                    e.PrintLine(" Test Page See the Arabic text Below WPC1256_ARABIC"),
                    enc.GetBytes("طباعة صفحة إختبار "),
                    e.PrintLine("\x1D\x56\x42\x00"),
                    e.CodePage(CodePage.WPC1256_ARABIC),
                    e.CenterAlign(),
                    e.PrintLine(" Test Page See the Arabic text Below WPC1256_ARABIC"),
                    enc.GetBytes("طباعة صفحة إختبار "),
                    e.PrintLine("\x1D\x56\x42\x00"),
                    e.CodePage(CodePage.PC720_ARABIC),
                    e.CenterAlign(),
                    e.PrintLine(" Test Page See the Arabic text Below PC720_ARABIC"),
                    enc.GetBytes("طباعة صفحة إختبار "),
                    e.PrintLine("\x1D\x56\x42\x00"),
                    e.CodePage(CodePage.PC720_ARABIC),
                    e.CenterAlign(),
                    e.PrintLine(" Test Page See the Arabic text Below PC720_ARABIC"),
                    enc.GetBytes("طباعة صفحة إختبار "),
                    e.PrintLine("\x1D\x56\x42\x00"),
                    e.CodePage(CodePage.PC864_ARABIC),
                    e.CenterAlign(),
                    e.PrintLine(" Test Page See the Arabic text Below PC864_ARABIC"),
                    enc.GetBytes("طباعة صفحة إختبار "),
                    e.PrintLine("\x1D\x56\x42\x00")
            );`

(ignore the paper cuts) Korean Characters are "핸 턱한" Result

this is the method I send it to the printer. I don't think I'm loosing any byte data:

    public static bool SendBytesToPrinter(string szPrinterName, byte[] data)
    {
        var pUnmanagedBytes = Marshal.AllocCoTaskMem(data.Length); // Allocate unmanaged memory
        Marshal.Copy(data, 0, pUnmanagedBytes, data.Length); // copy bytes into unmanaged memory
        var retval = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, data.Length);
        Marshal.FreeCoTaskMem(pUnmanagedBytes); // Free the allocated unmanaged memory

        return retval;
    }
AmerAlmadanydotNet commented 2 years ago

same problem ....

savindu-pasintha commented 2 years ago

you cant arabic text draw in canvas object and then you can pass canvas bitmap object to printer. it will be print as a image.

lerasah commented 2 years ago

you cant arabic text draw in canvas object and then you can pass canvas bitmap object to printer. it will be print as a image.

Hey Savindu bro - thanks for the reply. I was able to print arabic using a similar gimmick for now, but there are issues like font anti aliasing is not smooth. That's why I wanted to find the issue with the library method. SendBytesToPrinter

savindu-pasintha commented 2 years ago

also me , faced that issue.

savindu-pasintha commented 2 years ago

image see, image is not smoot, you are correct. these days I am also trying to fix that one.