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

How to print QRcode?

Open samchliu opened this issue 4 years ago • 3 comments

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

samchliu avatar Jan 25 '21 10:01 samchliu

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!

znoOb avatar Jan 25 '21 14:01 znoOb

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"))

rubendmribeiro avatar Feb 10 '21 11:02 rubendmribeiro

Hello. The code works fine but is there any way to resize the QRCode width - height;

ex the printed image to be 4.5 for size or some other code so i can fix the size..

Thanks in advance

kitsaras54 avatar Feb 24 '21 20:02 kitsaras54