All Projects → igorocampos → ESCPOS

igorocampos / ESCPOS

Licence: other
A ESC/POS Printer Commands Helper

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to ESCPOS

Vip.Printer
Biblioteca para realizar impressões (impressora não fiscal) utilizando comandos Esc/Bema, Esc/Daruma e Esc/Pos 🚀
Stars: ✭ 48 (+84.62%)
Mutual labels:  printer, escpos, sat, cfe
esc pos bluetooth
ESC/POS (thermal, receipt) printing for Flutter & Dart (Android/iOS)
Stars: ✭ 177 (+580.77%)
Mutual labels:  receipt, pos, esc
escpos-tools
Utilities to read ESC/POS print data
Stars: ✭ 145 (+457.69%)
Mutual labels:  escpos, receipt, pos
Escpos Php
PHP library for printing to ESC/POS-compatible thermal and impact printers
Stars: ✭ 1,851 (+7019.23%)
Mutual labels:  printer, barcode, escpos
escpos-coffee
Java library for ESC/POS printer
Stars: ✭ 172 (+561.54%)
Mutual labels:  qrcode, barcode, escpos
quickprinter
[Quick Printer] Created for the purpose of serving as a channel among other applications that require printing data on receipt printers using ESC / POS commands.
Stars: ✭ 99 (+280.77%)
Mutual labels:  printer, escpos, esc-pos
chrome-raw-print
Chrome app to enable raw printing from a browser
Stars: ✭ 57 (+119.23%)
Mutual labels:  printer, receipt, pos
taro-code
Taro Barcode & QRCode
Stars: ✭ 88 (+238.46%)
Mutual labels:  qrcode, barcode
ZZYQRCode
a scanner for QRCode barCode 最好用的ios二维码、条形码,扫描、生成框架,支持闪光灯,从相册获取,扫描音效等,高仿微信,微博
Stars: ✭ 124 (+376.92%)
Mutual labels:  qrcode, barcode
react-native-smart-code
Support React & ReactNative.In react-native,it's create base64 String,which is qrcode or barcode ,and without webview.In react,we use jsbarcode.
Stars: ✭ 14 (-46.15%)
Mutual labels:  qrcode, barcode
react-native-thermal-receipt-printer-image-qr
React native thermal receipt printer
Stars: ✭ 71 (+173.08%)
Mutual labels:  printer, qrcode
Esc pos printer
ESC/POS (thermal, receipt) printing for Flutter & Dart
Stars: ✭ 148 (+469.23%)
Mutual labels:  printer, pos
escpos-xml
JavaScript library that implements the thermal printer ESC / POS protocol and provides an XML interface for preparing templates for printing.
Stars: ✭ 37 (+42.31%)
Mutual labels:  printer, escpos
barcode-detector
Spec compliant polyfill of the Barcode Detection API 🤳
Stars: ✭ 31 (+19.23%)
Mutual labels:  qrcode, barcode
javascript-barcode
Dynamsoft Barcode Reader JavaScript SDK for package managers. PDF417, QR Code, DataMatrix, MaxiCode and more are supported.
Stars: ✭ 142 (+446.15%)
Mutual labels:  qrcode, barcode
Postscriptbarcode
Barcode Writer in Pure PostScript
Stars: ✭ 316 (+1115.38%)
Mutual labels:  printer, barcode
api2pdf.php
PHP client library for the Api2Pdf.com REST API - Convert HTML to PDF, URL to PDF, Office Docs to PDF, Merge PDFs, HTML to Image, URL to Image, HTML to Docx, HTML to Xlsx, PDF to HTML, Thumbnail preview of office files
Stars: ✭ 42 (+61.54%)
Mutual labels:  qrcode, barcode
android-zbar-sdk
🔗 android-zbar-sdk, provide jni source, so file and jar file used alone, gradle/maven remote dependencies.
Stars: ✭ 311 (+1096.15%)
Mutual labels:  qrcode, barcode
quicktill
Figure out where all the money and stock went to
Stars: ✭ 29 (+11.54%)
Mutual labels:  escpos, pos
barcode-server
Barcode Server for Barcode Client-Server android application
Stars: ✭ 40 (+53.85%)
Mutual labels:  qrcode, barcode

SourceLink Build Status GitHub code size in bytes NuGet GitHub FOSSA Status

ESCPOS

A ESC/POS Printer Commands Helper.

Installing via NuGet Package

The NuGet Package can be found here and you can install it with:

PM> Install-Package ESCPOS

Usage

All command methods will return a byte array that you should concatenate with the bytes of your data, and then send it all to your printer.

The Print extension method will send a byte array to the informed printer address, which can be something like COM3, LPT1, \\127.0.0.1\printer, 192.168.0.100:9100, etc. or even a path to a text file like ./print.txt.

There is also an Add and ToBytes extension methods located in the namespace ESCPOS.Utils. The first one for byte arrays, you can use it to concatenate 2 or more byte arrays just like this:

byte[] result = array1.Add(array2, array3, ..., arrayN);

There's also an overload to accept string parameters instead of byte arrays. It appends all strings into one new string and then converts it to a byte array. And an overload to accept the mix of byte arrays and strings parameters, since it's accepting object type parameters, this will ignore any parameter that is not one of them (e.g. int).

The second for strings, you can use it to convert a UTF-8 string to a byte array:

byte[] result = "Some string".ToBytes();

Examples

All examples will assume the using statements below:

using static ESCPOS.Commands;
using ESCPOS;
using ESCPOS.Utils;

QRCode

byte[] qrCodeCommand = PrintQRCode("Some data");
qrCodeCommand.Print("COM2");

Barcode

byte[] barCodeCommand = PrintBarCode(BarCodeType.EAN13, "9780201379624");
barCodeCommand.Print("192.168.0.100:9100");

Full CFe SAT Receipt

This example will assume that the variable cfe is a deserialized object from the CFe XML, and will print the receipt using its fields. Also this example will print a 32 columns receipt, which is ideal for 56mm paper roll.

var line = "--------------------------------";

byte[] array = LF;
array = array.Add(SelectCharSizeHeight(CharSizeHeight.Double), SelectJustification(Justification.Center));

if (cfe.infCFe.emit.xFant != null)
    array.Add(cfe.infCFe.emit.xFant);

array.Add(LF, SelectCharSizeHeight(CharSizeHeight.Normal), cfe.infCFe.emit.xNome,
          LF, $"{cfe.infCFe.emit.enderEmit.xLgr},{cfe.infCFe.emit.enderEmit.nro} {cfe.infCFe.emit.enderEmit.xBairro} - {cfe.infCFe.emit.enderEmit.xMun} {cfe.infCFe.emit.enderEmit.CEP}",
          LF, $"CNPJ: {cfe.infCFe.emit.CNPJ}",
          LF, $"IE: {cfe.infCFe.emit.IE}",
          LF, line, SelectCharSizeHeight(CharSizeHeight.Double), $"Extrato No. {cfe.infCFe.ide.nCFe}",
          LF, "CUPOM FISCAL ELETRONICO - SAT", SelectCharSizeHeight(CharSizeHeight.Normal),
          LF, LF);

if (!string.IsNullOrEmpty(cfe.infCFe.dest?.Item))
    array.Add(line, "CPF/CNPJ do Consumidor:", cfe.infCFe.dest.Item, LF);

array.Add(line, "#|COD|DESC|QTD|UN|VL UNIT R$|(VL TRIB R$)*|VL ITEM R$",
          LF, line, SelectJustification(Justification.Left));

int i = 1;
foreach (var det in cfe.infCFe.det)
{
    string prod = $"{det.prod.cProd} {det.prod.xProd} {det.prod.qCom:0.0##} {det.prod.uCom} X {det.prod.vUnCom:0.00#} {((det.imposto?.vItem12741 ?? 0) == 0 ? "" : $"({det.imposto.vItem12741:f2})*")}";
    array.Add($" {i++:D3} ");
    while (prod.Length > 20)
    {
        var wrap = prod.Length >= 20 ? prod.Substring(0,20) : prod;
        array.Add(wrap), LF, "     ");
        prod = prod.Substring(20);
    }
    array.Add(prod.PadRight(20), det.prod.vProd.ToString("f2").PadLeft(6), LF);
}

array.Add(LF);

if (cfe.infCFe.total.ICMSTot.vDesc > 0)
    array.Add($" Desconto R${cfe.infCFe.total.ICMSTot.vDesc.ToString("f2").PadLeft(19)}", LF);

if (cfe.infCFe.total.ICMSTot.vOutro > 0)
    array.Add($" Acrescimo R${cfe.infCFe.total.ICMSTot.vOutro.ToString("f2").PadLeft(18)}", LF);

array.Add(SelectCharSizeHeight(CharSizeHeight.Double), $" TOTAL R${cfe.infCFe.total.vCFe.ToString("f2").PadLeft(22)}", LF,
          SelectCharSizeHeight(CharSizeHeight.Normal), LF);

foreach (var mp in cfe.infCFe.pgto.MP)
{
    string description;
    switch (Convert.ToInt32(mp.cMP ?? "1"))
    {
        case 2:
            description = "Cheque";
            break;
        case 3:
            description = "Cartao de Credito";
            break;
        case 4:
            description = "Cartao de Debito";
            break;
        case 5:
            description = "Credito na Loja";
            break;
        case 10:
            description = "Vale Alimentacao";
            break;
        case 11:
            description = "Vale Refeicao";
            break;
        case 12:
            description = "Vale Presente";
            break;
        case 13:
            description = "Vale Combustivel";
            break;
        case 14:
            description = "Duplicata Mercantil";
            break;
        case 90:
            description = "Sem Pagamento";
            break;
        default:
            description = "Dinheiro";
            break;
    }

    array.Add($" {description.PadRight(18)}{mp.vMP.ToString("f2").PadLeft(12)}", LF);
}

String accessKey = cfe.infCFe.Id.Substring(3, 44);
array.Add($" Troco{cfe.infCFe.pgto.vTroco.ToString("f2").PadLeft(25)}", LF);

foreach (var obs in cfe.infCFe.infAdic.obsFisco)
    array.Add($" {obs.xCampo}-{obs.xTexto}", LF);

array.Add(line, "OBSERVACOES DO CONTRIBUINTE", LF);
foreach (var item in cfe.infCFe.infAdic.infCpl.Split(';'))
    array.Add(item, LF);

array.Add(LF, line, SelectCharSizeHeight(CharSizeHeight.Double), SelectJustification(Justification.Center), $"SAT No. {cfe.infCFe.ide.nserieSAT}",
          LF, SelectCharSizeHeight(CharSizeHeight.Normal), DateTime.ParseExact($"{cfe.infCFe.ide.dEmi} {cfe.infCFe.ide.hEmi}", "yyyyMMdd HHmmss", System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy HH:mm:ss"),
          LF, LF, SelectCharSizeHeight(CharSizeHeight.Double), accessKey,
          LF, LF, PrintBarCode(BarCodeType.CODE128, accessKey.Substring(0, 22), 30), PrintBarCode(BarCodeType.CODE128, accessKey.Substring(22), 30),
          LF, LF,
          PrintQRCode($"{accessKey}|{cfe.infCFe.ide.dEmi}{cfe.infCFe.ide.hEmi}|{cfe.infCFe.total.vCFe}|{cfe.infCFe.dest?.Item ?? ""}|{cfe.infCFe.ide.assinaturaQRCODE}"),
          SelectCharSizeHeight(CharSizeHeight.Normal),
          LF, line, LF, LF, LF);

array.Print(@"\\127.0.0.1\printer");

Considerations

This library will only accept UTF8 Encoding for Barcodes and QRCodes data.

When printing CODE128 barcodes, it will use automatically subset B, which supports numbers, upper and lower case letters and some additional characters.

You can see the changelog here.

License

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].