{"id":15593214,"url":"https://github.com/igorocampos/escpos","last_synced_at":"2025-10-10T17:39:36.049Z","repository":{"id":46641158,"uuid":"203989479","full_name":"igorocampos/ESCPOS","owner":"igorocampos","description":"A ESC/POS Printer Commands Helper","archived":false,"fork":false,"pushed_at":"2025-02-26T00:01:44.000Z","size":954,"stargazers_count":62,"open_issues_count":1,"forks_count":24,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-10T17:39:35.494Z","etag":null,"topics":["barcode","cfe","esc","esc-pos","escpos","hacktoberfest","pos","printer","qrcode","receipt","sat"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/igorocampos.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-23T11:56:13.000Z","updated_at":"2025-09-16T01:08:50.000Z","dependencies_parsed_at":"2025-04-07T11:20:42.121Z","dependency_job_id":null,"html_url":"https://github.com/igorocampos/ESCPOS","commit_stats":{"total_commits":113,"total_committers":8,"mean_commits":14.125,"dds":"0.11504424778761058","last_synced_commit":"062a1df37efb7b2904928ce8aebeacbd8872cb3e"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/igorocampos/ESCPOS","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorocampos%2FESCPOS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorocampos%2FESCPOS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorocampos%2FESCPOS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorocampos%2FESCPOS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igorocampos","download_url":"https://codeload.github.com/igorocampos/ESCPOS/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorocampos%2FESCPOS/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279004821,"owners_count":26083784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["barcode","cfe","esc","esc-pos","escpos","hacktoberfest","pos","printer","qrcode","receipt","sat"],"created_at":"2024-10-03T00:05:30.827Z","updated_at":"2025-10-10T17:39:36.021Z","avatar_url":"https://github.com/igorocampos.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![SourceLink](https://img.shields.io/badge/SourceLink-enabled-brightgreen)](https://github.com/dotnet/sourcelink)\r\n[![Build Status](https://dev.azure.com/igorocampos/PersonalProjects/_apis/build/status/igorocampos.ESCPOS?branchName=master)](https://dev.azure.com/igorocampos/PersonalProjects/_build?definitionId=1\u0026_a=summary)\r\n[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/igorocampos/ESCPOS)](#)\r\n[![NuGet](https://img.shields.io/nuget/v/ESCPOS)](http://www.nuget.org/packages/ESCPOS)\r\n[![GitHub](https://img.shields.io/badge/license-MIT-green)](ESCPOS/LICENSE)\r\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Figorocampos%2FESCPOS.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Figorocampos%2FESCPOS?ref=badge_shield)\r\n\r\n# ESCPOS\r\nA ESC/POS Printer Commands Helper.\r\n\r\n![](https://github.com/igorocampos/ESCPOS/blob/master/ESC_POS.png)\r\n\r\n# Installing via NuGet Package\r\n\r\nThe NuGet Package can be found [here](https://www.nuget.org/packages/ESCPOS/) and you can install it with:\r\n\r\n```powershell\r\nPM\u003e Install-Package ESCPOS\r\n```\r\n\r\n# Usage\r\nAll 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 using the `Print` extension method, which will send a byte array to the informed printer address. It 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`.\r\n\r\nThere is also 2 extension methods, `Add` and `ToBytes`, located in the namespace `ESCPOS.Utils`. \r\nThe first one can be used in byte arrays, so you can concatenate 2 or more byte arrays just like this:\r\n```cs\r\nbyte[] result = array1.Add(array2, array3, ..., arrayN);\r\n```\r\nIn addition there's an overload to the mentioned `Add` method that will accept string parameters instead of byte arrays. It appends all strings into one new string and then converts it to a byte array.\r\nAnd yet another overload to accept the mix of byte arrays and strings parameters, but since it's accepting an object type parameter, this will ignore any parameter that is not `string` or `byte[]` (e.g. `int`).\r\n\r\nWith `ToBytes` method you can convert a UTF-8 string to a byte array:\r\n```cs\r\nbyte[] result = \"Some string\".ToBytes();\r\n```\r\n\r\nAlternatively you can choose whatever Encoding you wish to use for that:\r\n```cs\r\nbyte[] result = \"汉字\".ToBytes(Encoding.GetEncoding(\"GBK\"));\r\n```\r\n*Just make sure your Printer has a corresponding CodePage for that Encoding!\r\n\r\n## Printer Class\r\nAs an alternative, if you'd like to instantiate a Printer class that will handle all about bytes, encoding, and even have printer specific features like an horizontal line or print text aligned to the left AND to the right in the same line, which is only possible by knowing the number of columns your printer has, you can use the `Printer` class and its methods.\r\n\r\n```cs\r\n//Instantiate printer with its details for encoding, column count and address\r\nvar printer = new Printer { Encoding = Encoding.UTF8, Columns = 32, Address = \"COM4\" };\r\n\r\n//Add all bytes to the Cache\r\nprinter.AddToCache(\r\n    printer.HorizontalLine,\r\n    LF,\r\n    printer.SameLineLeftAndRightAlignedText(\"Sample Product\", \"$10.99\"),\r\n    LF,\r\n    printer.HorizontalLine\r\n);\r\n\r\n//Send everything that is currently in the cache to the printer\r\nprinter.Print();\r\n```\r\n\r\n## Examples\r\n\r\nAll examples will assume the using statements below:\r\n```cs\r\nusing static ESCPOS.Commands;\r\nusing ESCPOS;\r\nusing ESCPOS.Utils;\r\n```\r\n\r\n### QRCode\r\n```cs\r\nbyte[] qrCodeCommand = QRCode(\"Some data\");\r\nqrCodeCommand.Print(\"COM2\");\r\n```\r\n\r\nOr using the Extension Method\r\n\r\n```cs\r\nstring data = \"Some data\";\r\ndata.ToQRCode().Print(\"COM2\");\r\n```\r\n\r\n\r\n### Barcode\r\n```cs\r\nbyte[] barCodeCommand = Barcode(BarCodeType.EAN13, \"9780201379624\");\r\nbarCodeCommand.Print(\"192.168.0.100:9100\");\r\n```\r\n\r\nOr using the Extension Method\r\n\r\n```cs\r\nstring code = \"9780201379624\";\r\ncode.ToBarcode(BarCodeType.EAN13).Print(\"192.168.0.100:9100\");\r\n```\r\n\r\n\r\n### Formatted Text\r\n```cs\r\nbyte[] cmd = AlignToCenter.Add(CharSizeDoubleHeight, \"Fancy Title\");\r\ncmd.Print(@\"\\\\127.0.0.1\\printer\");\r\n```\r\n### Example using Printer class\r\n```cs\r\nvar printer = new Printer { Encoding = Encoding.UTF8, Columns = 32, Address = \"192.168.0.100:9100\" };\r\nprinter.AddToCache(\r\n    printer.HorizontalDoubleLine,\r\n    LF,\r\n    printer.SameLineLeftAndRightAlignedText(\"Product Name\", \"Price\"),\r\n    LF,\r\n    printer.HorizontalLine,\r\n    LF,\r\n    printer.SameLineLeftAndRightAlignedText(\"Sample Product\", \"$10.99\"),\r\n    LF,\r\n    printer.SameLineLeftAndRightAlignedText(\"Sample Product with a very long description\", \"$0.01\"),\r\n    LF,\r\n    AlignToRight,\r\n    \"----------\",\r\n    LF,\r\n    CharSizeDoubleHeight,\r\n    \"$11.00\",\r\n    CharSizeReset,\r\n    LF,\r\n    \"----------\",\r\n    AlignToLeft,\r\n    LF,\r\n    printer.HorizontalDoubleLine\r\n);\r\nprinter.Print();\r\n```\r\n\r\n### Full CFe SAT Receipt without using Printer class\r\nThis example will assume that the variable `cfe` is a deserialized object from the [CFe](https://portal.fazenda.sp.gov.br/servicos/sat) XML, and will print the receipt using its fields.\r\nAlso this example will print a 32 columns receipt, which is ideal for 56mm paper roll.\r\n```cs\r\n var line = \"--------------------------------\";\r\n\r\n byte[] array = LF;\r\n array = array.Add(CharSizeDoubleHeight, AlignToCenter);\r\n\r\n if (cfe.infCFe.emit.xFant != null)\r\n     array.Add(cfe.infCFe.emit.xFant);\r\n\r\n array.Add(LF, CharSizeReset, cfe.infCFe.emit.xNome,\r\n           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}\",\r\n           LF, $\"CNPJ: {cfe.infCFe.emit.CNPJ}\",\r\n           LF, $\"IE: {cfe.infCFe.emit.IE}\",\r\n           LF, line, CharSizeDoubleHeight, $\"Extrato No. {cfe.infCFe.ide.nCFe}\",\r\n           LF, \"CUPOM FISCAL ELETRONICO - SAT\", CharSizeReset,\r\n           LF, LF);\r\n\r\n if (!string.IsNullOrEmpty(cfe.infCFe.dest?.Item))\r\n     array.Add(line, \"CPF/CNPJ do Consumidor:\", cfe.infCFe.dest.Item, LF);\r\n\r\n array.Add(line, \r\n           \"#|COD|DESC|QTD|UN|VL UNIT R$|(VL TRIB R$)*|VL ITEM R$\", LF, \r\n           line, \r\n           AlignLeft);\r\n\r\n int i = 1;\r\n foreach (var det in cfe.infCFe.det)\r\n {\r\n     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})*\")}\";\r\n     array.Add($\" {i++:D3} \");\r\n     while (prod.Length \u003e 20)\r\n     {\r\n         var wrap = prod.Length \u003e= 20 ? prod.Substring(0, 20) : prod;\r\n         array.Add(wrap), LF, \"     \");\r\n         prod = prod.Substring(20);\r\n     }\r\n     array.Add(prod.PadRight(20), det.prod.vProd.ToString(\"f2\").PadLeft(6), LF);\r\n }\r\n\r\n array.Add(LF);\r\n\r\n if (cfe.infCFe.total.ICMSTot.vDesc \u003e 0)\r\n     array.Add($\" Desconto R${cfe.infCFe.total.ICMSTot.vDesc.ToString(\"f2\").PadLeft(19)}\", LF);\r\n\r\n if (cfe.infCFe.total.ICMSTot.vOutro \u003e 0)\r\n     array.Add($\" Acrescimo R${cfe.infCFe.total.ICMSTot.vOutro.ToString(\"f2\").PadLeft(18)}\", LF);\r\n\r\n array.Add(CharSizeDoubleHeight, $\" TOTAL R${cfe.infCFe.total.vCFe.ToString(\"f2\").PadLeft(22)}\", LF,\r\n           CharSizeReset, LF);\r\n\r\n foreach (var mp in cfe.infCFe.pgto.MP)\r\n {\r\n     string description;\r\n     switch (Convert.ToInt32(mp.cMP ?? \"1\"))\r\n     {\r\n         case 2:\r\n             description = \"Cheque\";\r\n             break;\r\n         case 3:\r\n             description = \"Cartao de Credito\";\r\n             break;\r\n         case 4:\r\n             description = \"Cartao de Debito\";\r\n             break;\r\n         case 5:\r\n             description = \"Credito na Loja\";\r\n             break;\r\n         case 10:\r\n             description = \"Vale Alimentacao\";\r\n             break;\r\n         case 11:\r\n             description = \"Vale Refeicao\";\r\n             break;\r\n         case 12:\r\n             description = \"Vale Presente\";\r\n             break;\r\n         case 13:\r\n             description = \"Vale Combustivel\";\r\n             break;\r\n         case 14:\r\n             description = \"Duplicata Mercantil\";\r\n             break;\r\n         case 90:\r\n             description = \"Sem Pagamento\";\r\n             break;\r\n         default:\r\n             description = \"Dinheiro\";\r\n             break;\r\n     }\r\n\r\n     array.Add($\" {description.PadRight(18)}{mp.vMP.ToString(\"f2\").PadLeft(12)}\", LF);\r\n }\r\n\r\n String accessKey = cfe.infCFe.Id.Substring(3, 44);\r\n array.Add($\" Troco{cfe.infCFe.pgto.vTroco.ToString(\"f2\").PadLeft(25)}\", LF);\r\n\r\n foreach (var obs in cfe.infCFe.infAdic.obsFisco)\r\n     array.Add($\" {obs.xCampo}-{obs.xTexto}\", LF);\r\n\r\n array.Add(line, \"OBSERVACOES DO CONTRIBUINTE\", LF);\r\n foreach (var item in cfe.infCFe.infAdic.infCpl.Split(';'))\r\n     array.Add(item, LF);\r\n\r\n array.Add(LF, line, CharSizeDoubleHeight, AlignTOCenter, $\"SAT No. {cfe.infCFe.ide.nserieSAT}\",\r\n           LF, CharSizeReset, DateTime.ParseExact($\"{cfe.infCFe.ide.dEmi} {cfe.infCFe.ide.hEmi}\", \"yyyyMMdd HHmmss\", System.Globalization.CultureInfo.InvariantCulture).ToString(\"dd/MM/yyyy HH:mm:ss\"),\r\n           LF, LF, CharSizeDoubleHeight, accessKey,\r\n           LF, LF, accessKey.Substring(0, 22).ToBarcode(BarCodeType.CODE128, 30), accessKey.Substring(22).ToBarcode(BarCodeType.CODE128, 30),\r\n           LF, LF,\r\n           $\"{accessKey}|{cfe.infCFe.ide.dEmi}{cfe.infCFe.ide.hEmi}|{cfe.infCFe.total.vCFe}|{cfe.infCFe.dest?.Item ?? \"\"}|{cfe.infCFe.ide.assinaturaQRCODE}\".ToQRCode(),\r\n           CharSizeReset,\r\n           LF, line, LF, LF, LF);\r\n\r\n array.Print(@\"\\\\127.0.0.1\\printer\");\r\n```\r\n\r\n# Considerations\r\nWhen printing CODE128 barcodes, it will use automatically subset B, which supports numbers, upper and lower case letters and some additional characters.\r\n\r\nYou can see the changelog [here](CHANGELOG.md).\r\n\r\n\r\n## License\r\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Figorocampos%2FESCPOS.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Figorocampos%2FESCPOS?ref=badge_large)\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorocampos%2Fescpos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figorocampos%2Fescpos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorocampos%2Fescpos/lists"}