{"id":22393505,"url":"https://github.com/andrey-ushakov/esc_pos_utils","last_synced_at":"2025-04-04T07:05:40.628Z","repository":{"id":40549715,"uuid":"246337566","full_name":"andrey-ushakov/esc_pos_utils","owner":"andrey-ushakov","description":"Basic Flutter/Dart classes for ESC/POS printing","archived":false,"fork":false,"pushed_at":"2024-06-04T07:12:21.000Z","size":57,"stargazers_count":157,"open_issues_count":110,"forks_count":344,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-28T06:03:53.447Z","etag":null,"topics":["dart","esc","flutter","pos","pos-printing","receipt-printer","thermal-printer"],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrey-ushakov.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2020-03-10T15:26:12.000Z","updated_at":"2025-03-08T11:35:56.000Z","dependencies_parsed_at":"2024-06-18T15:30:06.189Z","dependency_job_id":"beabbddd-2a8e-4011-8e30-76cc884ccd01","html_url":"https://github.com/andrey-ushakov/esc_pos_utils","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrey-ushakov%2Fesc_pos_utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrey-ushakov%2Fesc_pos_utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrey-ushakov%2Fesc_pos_utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrey-ushakov%2Fesc_pos_utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrey-ushakov","download_url":"https://codeload.github.com/andrey-ushakov/esc_pos_utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135142,"owners_count":20889420,"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","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":["dart","esc","flutter","pos","pos-printing","receipt-printer","thermal-printer"],"created_at":"2024-12-05T05:05:51.811Z","updated_at":"2025-04-04T07:05:40.606Z","avatar_url":"https://github.com/andrey-ushakov.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esc_pos_utils\n\n[![Pub Version](https://img.shields.io/pub/v/esc_pos_utils)](https://pub.dev/packages/esc_pos_utils)\n\nBase Flutter/Dart classes for ESC/POS printing. `Generator` class generates ESC/POS commands that can be sent to a thermal printer.\n\nThis is the \"base\" library that used for:\n\n- Flutter WiFi/Ethernet printing: [esc_pos_printer](https://github.com/andrey-ushakov/esc_pos_printer)\n- Flutter Bluetooth printing: [esc_pos_bluetooth](https://github.com/andrey-ushakov/esc_pos_bluetooth)\n\n## Main Features\n\n- Connect to Wi-Fi / Ethernet printers\n- Simple text printing using _text_ method\n- Tables printing using _row_ method\n- Text styling:\n  - size, align, bold, reverse, underline, different fonts, turn 90°\n- Print images\n- Print barcodes\n  - UPC-A, UPC-E, JAN13 (EAN13), JAN8 (EAN8), CODE39, ITF (Interleaved 2 of 5), CODABAR (NW-7), CODE128\n- Paper cut (partial, full)\n- Beeping (with different duration)\n- Paper feed, reverse feed\n\n**Note**: Your printer may not support some of the presented features (some styles, partial/full paper cutting, reverse feed, barcodes...).\n\n## Generate a Ticket\n\n### Simple ticket with styles:\n\n```dart\nList\u003cint\u003e testTicket() {\n  final List\u003cint\u003e bytes = [];\n  // Using default profile\n  final profile = await CapabilityProfile.load();\n  final generator = Generator(PaperSize.mm80, profile);\n  List\u003cint\u003e bytes = [];\n\n  bytes += generator.text(\n      'Regular: aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ');\n  bytes += generator.text('Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ',\n      styles: PosStyles(codeTable: PosCodeTable.westEur));\n  bytes += generator.text('Special 2: blåbærgrød',\n      styles: PosStyles(codeTable: PosCodeTable.westEur));\n\n  bytes += generator.text('Bold text', styles: PosStyles(bold: true));\n  bytes += generator.text('Reverse text', styles: PosStyles(reverse: true));\n  bytes += generator.text('Underlined text',\n      styles: PosStyles(underline: true), linesAfter: 1);\n  bytes += generator.text('Align left', styles: PosStyles(align: PosAlign.left));\n  bytes += generator.text('Align center', styles: PosStyles(align: PosAlign.center));\n  bytes += generator.text('Align right',\n      styles: PosStyles(align: PosAlign.right), linesAfter: 1);\n\n  bytes += generator.text('Text size 200%',\n      styles: PosStyles(\n        height: PosTextSize.size2,\n        width: PosTextSize.size2,\n      ));\n\n  bytes += generator.feed(2);\n  bytes += generator.cut();\n  return bytes;\n}\n```\n\n### Print a table row:\n\n```dart\ngenerator.row([\n    PosColumn(\n      text: 'col3',\n      width: 3,\n      styles: PosStyles(align: PosAlign.center, underline: true),\n    ),\n    PosColumn(\n      text: 'col6',\n      width: 6,\n      styles: PosStyles(align: PosAlign.center, underline: true),\n    ),\n    PosColumn(\n      text: 'col3',\n      width: 3,\n      styles: PosStyles(align: PosAlign.center, underline: true),\n    ),\n  ]);\n```\n\n### Print an image:\n\nThis package implements 3 ESC/POS functions:\n\n- `ESC *` - print in column format\n- `GS v 0` - print in bit raster format (obsolete)\n- `GS ( L` - print in bit raster format\n\nNote that your printer may support only some of the above functions.\n\n```dart\nimport 'dart:io';\nimport 'package:image/image.dart';\n\nfinal ByteData data = await rootBundle.load('assets/logo.png');\nfinal Uint8List bytes = data.buffer.asUint8List();\nfinal Image image = decodeImage(bytes);\n// Using `ESC *`\ngenerator.image(image);\n// Using `GS v 0` (obsolete)\ngenerator.imageRaster(image);\n// Using `GS ( L`\ngenerator.imageRaster(image, imageFn: PosImageFn.graphics);\n```\n\n### Print a Barcode:\n\n```dart\nfinal List\u003cint\u003e barData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 4];\ngenerator.barcode(Barcode.upcA(barData));\n```\n\n### Print a QR Code:\n\nUsing native ESC/POS commands:\n\n```dart\ngenerator.qrcode('example.com');\n```\n\nTo print a QR Code as an image (if your printer doesn't support native commands), add [qr_flutter](https://pub.dev/packages/qr_flutter) and [path_provider](https://pub.dev/packages/path_provider) as a dependency in your `pubspec.yaml` file.\n\n```dart\nString qrData = \"google.com\";\nconst double qrSize = 200;\ntry {\n  final uiImg = await QrPainter(\n    data: qrData,\n    version: QrVersions.auto,\n    gapless: false,\n  ).toImageData(qrSize);\n  final dir = await getTemporaryDirectory();\n  final pathName = '${dir.path}/qr_tmp.png';\n  final qrFile = File(pathName);\n  final imgFile = await qrFile.writeAsBytes(uiImg.buffer.asUint8List());\n  final img = decodeImage(imgFile.readAsBytesSync());\n\n  generator.image(img);\n} catch (e) {\n  print(e);\n}\n```\n\n## Using Code Tables\n\nDifferent printers support different sets of code tables. Some printer models are defined in `CapabilityProfile` class. So, if you want to change the default code table, it's important to choose the right profile:\n\n```dart\n// Xprinter XP-N160I\nfinal profile = await CapabilityProfile.load('XP-N160I');\nfinal generator = Generator(PaperSize.mm80, profile);\nbytes += generator.setGlobalCodeTable('CP1252');\n```\n\nAll available profiles can be retrieved by calling :\n\n```dart\nfinal profiles = await CapabilityProfile.getAvailableProfiles();\n```\n\n## How to Help\n\n- Add a CapabilityProfile to support your printer's model. A new profile should be added to `lib/resources/capabilities.json` file\n- Test your printer and add it in the table: [Wifi/Network printer](https://github.com/andrey-ushakov/esc_pos_printer/blob/master/printers.md) or [Bluetooth printer](https://github.com/andrey-ushakov/esc_pos_bluetooth/blob/master/printers.md)\n- Test and report bugs\n- Share your ideas about what could be improved (code optimization, new features...)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrey-ushakov%2Fesc_pos_utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrey-ushakov%2Fesc_pos_utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrey-ushakov%2Fesc_pos_utils/lists"}