Created
August 12, 2019 11:43
-
-
Save simix-felipebaltazar/15da0ed36cb857c0749c07d2b76c4bfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Inovadora.GVIS.Services.Interfaces; | |
using System.Text; | |
namespace Inovadora.GVIS.Services | |
{ | |
// | |
// Summary: | |
// /// Classe responsável pelo service. /// | |
// https://www.activeplus.com/products/ethernet-pos/samples/cs-tcpip | |
// https://liana-ali.blogspot.com/2018/09/escpos-print-qr-code-in-receipt.html | |
// | |
public class FactoryDataToPrintService : IFactoryDataToPrintService | |
{ | |
const char ESC = '\x1b'; | |
const char FS = '\x1c'; | |
const char GS = '\x1d'; | |
string ENABLE_ALIGN_CENTER = ESC + "a" + (char)1; | |
string DISABLE_ALIGN_CENTER = ESC + "a" + (char)0; | |
string ENABLE_BOLD = ESC + "E" + (char)1; | |
string DISABLE_BOLD = ESC + "E" + (char)0; | |
public byte[] Factory() | |
{ | |
StringBuilder builder = new StringBuilder(ESC + "@"); | |
builder.Append(ENABLE_ALIGN_CENTER); | |
builder.Append(ENABLE_BOLD); | |
builder.Append("G-VIS\n"); | |
builder.Append("www.inovadora.com.br\n\n"); | |
builder.Append(DISABLE_ALIGN_CENTER); | |
builder.Append(DISABLE_BOLD); | |
builder.Append("This sample text is sent from a C# program\n"); | |
string QrData = "www.inovadora.com.br"; | |
string builderQrCode = string.Empty; | |
Encoding m_encoding = Encoding.GetEncoding("iso-8859-1"); | |
int store_len = (QrData).Length + 3; | |
byte store_pL = (byte)(store_len % 256); | |
byte store_pH = (byte)(store_len / 256); | |
builderQrCode += m_encoding.GetString(new byte[] { 29, 40, 107, 4, 0, 49, 65, 50, 0 }); | |
builderQrCode += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 67, 8 }); | |
builderQrCode += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 69, 48 }); | |
builderQrCode += m_encoding.GetString(new byte[] { 29, 40, 107, store_pL, store_pH, 49, 80, 48 }); | |
builderQrCode += QrData; | |
builderQrCode += m_encoding.GetString(new byte[] { 29, 40, 107, 3, 0, 49, 81, 48 }); | |
builder.Append(ENABLE_ALIGN_CENTER); | |
builder.Append(builderQrCode); | |
builder.Append(DISABLE_ALIGN_CENTER); | |
// Feed and cut paper | |
builder.Append(GS + "V\x41\0"); | |
return Encoding.Default.GetBytes(builder.ToString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment