mtmsuhail / ESC-POS-USB-NET

This project is a simple .NET (C#) Implementation of the Epson ESC/POS Printing using USB Device Driver.
MIT License
205 stars 88 forks source link

How to print QRcode? #24

Open samchliu opened 3 years ago

samchliu commented 3 years ago

Hi, I'm a beginner, how can I use QrCode function?

Printer printer = new Printer("myPrinter");
printer.QrCode("https://www.google.com/");
printer.PrintDocument();

I expect it will print the qrcode image, but it print a line like this 1A21C1E01P0https://www.google.com/1Q0

thanks

znoOb commented 3 years ago

try this (esc/pos) ...... PrintQR("http://www.google.com"); /// calling function ...... private string PrintQR(string _qr) { Encoding m_encoding = Encoding.GetEncoding("iso-8859-1"); string buffer = ""; int store_len = (_qr).Length + 3; byte store_pL = (byte)(store_len % 256); byte store_pH = (byte)(store_len / 256); buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 4, 0, 49, 65, 50, 0 }); buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 67, 8 }); buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 69, 48 }); buffer += m_encoding.GetString(new byte[] { 29, 40, 107, store_pL, store_pH, 49, 80, 48 }); buffer += _qr; buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 81, 48 }); StringtoPrint.AppendLine(buffer); }

Good luck!

rubendmribeiro commented 3 years ago

try this (esc/pos) ...... PrintQR("http://www.google.com"); /// calling function ...... private string PrintQR(string _qr) { Encoding m_encoding = Encoding.GetEncoding("iso-8859-1"); string buffer = ""; int store_len = (_qr).Length + 3; byte store_pL = (byte)(store_len % 256); byte store_pH = (byte)(store_len / 256); buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 4, 0, 49, 65, 50, 0 }); buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 67, 8 }); buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 69, 48 }); buffer += m_encoding.GetString(new byte[] { 29, 40, 107, store_pL, store_pH, 49, 80, 48 }); buffer += _qr; buffer += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 81, 48 }); StringtoPrint.AppendLine(buffer); }

Good luck!

Hi znoOb, i tried your code and still not working.. maybe i made something wrong, im working on VB.NET , here's what i did..

Dim m_encoding As Encoding = Encoding.GetEncoding("iso-8859-1") Dim buffer As String = "" Dim store_len As Integer = (_qr).Length + 3 Dim store_pL As Byte = CByte((store_len Mod 256)) Dim store_pH As Byte = CByte((store_len / 256)) buffer += m_encoding.GetString(New Byte() {29, 40, 107, 4, 0, 49, 65, 50, 0}) buffer += m_encoding.GetString(New Byte() {29, 40, 107, 3, 0, 49, 67, 8}) buffer += m_encoding.GetString(New Byte() {29, 40, 107, 3, 0, 49, 69, 48}) buffer += m_encoding.GetString(New Byte() {29, 40, 107, store_pL, store_pH, 49, 80, 48}) buffer += _qr buffer += m_encoding.GetString(New Byte() {29, 40, 107, 3, 0, 49, 81, 48}) Return buffer

And in the printer code im using this: printer.Append(PrintQR("www.google.pt"))