esc_pos_printer 3.1.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 94

esc_pos_printer #

Pub Version

The library allows to print receipts using an ESC/POS thermal WiFi/Ethernet printer. For Bluetooth printers, use esc_pos_bluetooth library.

It can be used in Flutter or pure Dart projects. For Flutter projects, both Android and iOS are supported.

To scan for printers in your network, consider using ping_discover_network package. Note that most of the ESC/POS printers by default listen on port 9100.

TODO (PRs are welcomed!) #

  • Print QR Codes using the GS ( k command (printing QR code from an image already supported)
  • PDF-417 Barcodes using the GS ( k command
  • Line spacing using the ESC 3 <n> command

How to Help #

  • Test your printer and add it in the table: Wifi/Network printer or Bluetooth printer
  • Test and report bugs
  • Share your ideas about what could be improved (code optimization, new features...)
  • PRs are welcomed!

Tested Printers #

Here are some printers tested with this library. Please add the models you have tested to maintain and improve this library and help others to choose the right printer.

Generate a Ticket #

Simple Ticket with Styles: #

Ticket testTicket() {
  final Ticket ticket = Ticket(PaperSize.mm80);

  ticket.text(
      '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');
  ticket.text('Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ',
      styles: PosStyles(codeTable: PosCodeTable.westEur));
  ticket.text('Special 2: blåbærgrød',
      styles: PosStyles(codeTable: PosCodeTable.westEur));

  ticket.text('Bold text', styles: PosStyles(bold: true));
  ticket.text('Reverse text', styles: PosStyles(reverse: true));
  ticket.text('Underlined text',
      styles: PosStyles(underline: true), linesAfter: 1);
  ticket.text('Align left', styles: PosStyles(align: PosAlign.left));
  ticket.text('Align center', styles: PosStyles(align: PosAlign.center));
  ticket.text('Align right',
      styles: PosStyles(align: PosAlign.right), linesAfter: 1);

  ticket.text('Text size 200%',
      styles: PosStyles(
        height: PosTextSize.size2,
        width: PosTextSize.size2,
      ));

  ticket.feed(2);
  ticket.cut();
  return ticket;
}

You can find more examples here: esc_pos_utils.

import 'package:esc_pos_printer/esc_pos_printer.dart';

final PrinterNetworkManager printerManager = PrinterNetworkManager();
printerManager.selectPrinter('192.168.0.123', port: 9100);
final PosPrintResult res = await printerManager.printTicket(testTicket());

print('Print result: ${res.msg}');

For a complete example, check example/example.dart and example/discover_printers.

Test Print #

test receipttest receipt

[3.1.6] #

  • Bump esc_pos_utils

[3.1.5] #

  • Updated esc_pos_utils package version to 0.3.5.

[3.1.4] #

  • Updated esc_pos_utils package version to 0.3.4.

[3.1.3] #

  • Updated esc_pos_utils package version to 0.3.3.

[3.1.2] #

  • Updated esc_pos_utils package version to 0.3.2.

[3.1.1] #

  • Updated esc_pos_utils package version to 0.3.1 (Open Cash Drawer).

[3.1.0] #

  • Updated esc_pos_utils package version to 0.3.0 (Image and Barcode alignment).

[3.0.2] #

  • Updated esc_pos_utils package version

[3.0.1] #

  • Removed rxdart dependency

[3.0.0] #

  • Basic ESC/POS classes moved to esc_pos_utils library
  • Bluetooth printing moved to esc_pos_bluetooth library
  • This library is used to print using a WiFi/Ethernet printer

[2.1.2] #

  • Bluetooth printing support for Android

[2.1.0] #

  • Printer class replaced by PrinterNetworkManager
  • Generate tickets using Ticket class
  • Unified interfaces for WiFi/Bluetooth printings
  • Better error handling using PosPrintResult class
  • Examples updated

[2.0.0] #

  • Bluetooth printers support (beta version, iOS-only)

[1.5.0] #

  • printlnMixedKanji merged to println
  • Can print rows/cols with mixed chinese/non-chinese texts

[1.4.1] #

  • Print mixed (chinese + latin) text. Only for printers supporting Kanji mode

[1.4.0] #

  • Print barcodes

[1.3.2] #

  • Added alternative printImageRaster method using (GS v 0) obsolete command
  • Code refactoring

[1.3.1] #

  • Removed raw lib
  • Code refactoring

[1.3.0] #

  • Image printing method has been improved
  • Using ESC * command to print images instead of outdated GS v 0
  • Added print image Flutter example

[1.2.0] #

  • Printing images (beta)

[1.1.3] #

  • printCodeTable bug fixed
  • Updated test print example

[1.1.2] #

  • Better alignment

[1.1.1] #

  • Fixed columns alignment bug

[1.1.0] #

  • Added code page support

[1.0.2] #

  • Send raw command(s)
  • Turn 90° clockwise rotation mode on/off
  • Flutter example: discover active Wi-Fi printers
  • Select character code table

[1.0.1] #

  • exported PosColumn

[1.0.0] #

  • Removed PosString class
  • Added PosStyles and PosColumn classes
  • Updated examples and readme

[0.9.0] - [0.9.1] #

  • Initial release
  • Added basic functions (cut paper, write line, ...)
  • Text styling (bold, underline, reverted, ...)
  • Text align
  • Table row printing (up to 12 columns of different width)

example/example.dart

// import 'dart:io';
// import 'dart:typed_data';
// import 'package:flutter/services.dart';
// import 'package:image/image.dart';
import 'package:esc_pos_printer/esc_pos_printer.dart';
import 'package:esc_pos_utils/esc_pos_utils.dart';

void main() async {
  final PrinterNetworkManager printerManager = PrinterNetworkManager();
  // To discover network printers in your subnet, consider using
  // ping_discover_network package (https://pub.dev/packages/ping_discover_network).
  // Note that most of ESC/POS printers are available on port 9100 by default.
  printerManager.selectPrinter('192.168.0.123', port: 9100);

  final PosPrintResult res =
      await printerManager.printTicket(await testTicket());
  print('Print result: ${res.msg}');
}

Future<Ticket> testTicket() async {
  final Ticket ticket = Ticket(PaperSize.mm80);

  ticket.text(
      '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');
  ticket.text('Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ',
      styles: PosStyles(codeTable: PosCodeTable.westEur));
  ticket.text('Special 2: blåbærgrød',
      styles: PosStyles(codeTable: PosCodeTable.westEur));

  ticket.text('Bold text', styles: PosStyles(bold: true));
  ticket.text('Reverse text', styles: PosStyles(reverse: true));
  ticket.text('Underlined text',
      styles: PosStyles(underline: true), linesAfter: 1);
  ticket.text('Align left', styles: PosStyles(align: PosAlign.left));
  ticket.text('Align center', styles: PosStyles(align: PosAlign.center));
  ticket.text('Align right',
      styles: PosStyles(align: PosAlign.right), linesAfter: 1);

  ticket.row([
    PosColumn(
      text: 'col3',
      width: 3,
      styles: PosStyles(align: PosAlign.center, underline: true),
    ),
    PosColumn(
      text: 'col6',
      width: 6,
      styles: PosStyles(align: PosAlign.center, underline: true),
    ),
    PosColumn(
      text: 'col3',
      width: 3,
      styles: PosStyles(align: PosAlign.center, underline: true),
    ),
  ]);

  ticket.text('Text size 200%',
      styles: PosStyles(
        height: PosTextSize.size2,
        width: PosTextSize.size2,
      ));

  // Print image
  // final ByteData data = await rootBundle.load('assets/logo.png');
  // final Uint8List bytes = data.buffer.asUint8List();
  // final Image image = decodeImage(bytes);
  // ticket.image(image);
  // Print image using alternative commands
  // ticket.imageRaster(image);
  // ticket.imageRaster(image, imageFn: PosImageFn.graphics);

  // Print barcode
  final List<int> barData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 4];
  ticket.barcode(Barcode.upcA(barData));

  // Print mixed (chinese + latin) text. Only for printers supporting Kanji mode
  // ticket.text(
  //   'hello ! 中文字 # world @ éphémère &',
  //   styles: PosStyles(codeTable: PosCodeTable.westEur),
  //   containsChinese: true,
  // );

  ticket.feed(2);

  ticket.cut();
  return ticket;
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  esc_pos_printer: ^3.1.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:esc_pos_printer/esc_pos_printer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
89
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
esc_pos_utils ^0.3.6 0.3.6
flutter 0.0.0
Transitive dependencies
archive 2.0.13
args 1.6.0
charcode 1.1.3
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
gbk_codec 0.3.2
hex 0.1.2
html 0.14.0+3
image 2.1.12
meta 1.1.8
path 1.6.4
petitparser 3.0.2
sky_engine 0.0.99
source_span 1.7.0
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
xml 3.7.0 4.1.0
Dev dependencies
flutter_test