How To Print QRCode in Thermal Printer

kelputoo 1 Reputation point
2021-11-02T15:22:24.02+00:00

Hi, can anyone help me with this situation? I'm in need of help printing a QR code using Xamarin.Forms (iOS and Android) (I just need the Android version).

I have an Thermal Printer, and im already printing text through the BluetoothSocket, and i can print QRCodes, but only small QRCodes, if i print a QRCode with more than X characters it will send a QRCode that is not well formated and the camera can't read it. Here's the code that i have so far.

var byteslist = new List<byte>();

                            byte[] qrBytes = System.Text.Encoding.ASCII.GetBytes(qrcode);
                            int dataLength = qrBytes.Length + 3;
                            byte dataPL = (byte)(dataLength % 256);
                            byte dataPH = (byte)(dataLength / 256);
                            var bytes = new List<byte>();

                        bytes.AddRange(new byte[] { 0x1D, 0x28, 0x6b, 0x04, 0x00, 0x31, 0x41, 0x33, 0x00 });
                        bytes.AddRange(new byte[] { 0x1D, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x05 });
                        bytes.AddRange(new byte[] { 0x1D, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x45, 0x30 }); 
                        bytes.AddRange(new byte[] { 0x1D, 0x28, 0x6B, dataPL, dataPH, 0x31, 0x50, 0x30 }); 
                        bytes.AddRange(qrBytes);
                        bytes.AddRange(new byte[] { 0x1D, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x30 });


                            await socket.OutputStream.WriteAsync(bytes.ToArray(), 0, bytes.Count);
                            socket.Close();
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,373 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,244 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Carl john Lopez 1 Reputation point
    2022-01-17T07:01:18.9+00:00

    do you have Github repo of your code?

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.