esc_pos_printer 1.5.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 93

esc_pos_printer #

Pub

The library allows to print receipts using a ESC/POS (usually thermal) network printer.

[pub.dev page] | [Documentation]

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

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

Main Features #

  • Connect to Wi-Fi printers
  • Simple text printing using println method
  • Tables printing using printRow method
  • Text styling:
    • size, align, bold, reverse, underline, different fonts, turn 90°
  • Print images
  • Print barcodes
    • UPC-A, UPC-E, JAN13 (EAN13), JAN8 (EAN8), CODE39, ITF (Interleaved 2 of 5), CODABAR (NW-7)
  • Paper cut (partial, full)
  • Beeping (with different duration)
  • Paper feed, reverse feed

Note: Your printer may not support some of the presented features (especially for underline styles, partial/full paper cutting, reverse feed, ...).

Getting Started #

import 'package:esc_pos_printer/esc_pos_printer.dart';

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

    printer.println('Bold text', styles: PosStyles(bold: true));
    printer.println('Reverse text', styles: PosStyles(reverse: true));
    printer.println('Underlined text',
        styles: PosStyles(underline: true), linesAfter: 1);

    printer.println('Align left', styles: PosStyles(align: PosTextAlign.left));
    printer.println('Align center',
        styles: PosStyles(align: PosTextAlign.center));
    printer.println('Align right',
        styles: PosStyles(align: PosTextAlign.right), linesAfter: 1);
    
    printer.println('Text size 200%',
        styles: PosStyles(
          height: PosTextSize.size2,
          width: PosTextSize.size2,
        ));

    printer.cut();
    printer.disconnect();
  });

Print table row:

printer.printRow([
      PosColumn(
        text: 'col3',
        width: 3,
        styles: PosStyles(align: PosTextAlign.center, underline: true),
      ),
      PosColumn(
        text: 'col6',
        width: 6,
        styles: PosStyles(align: PosTextAlign.center, underline: true),
      ),
      PosColumn(
        text: 'col3',
        width: 3,
        styles: PosStyles(align: PosTextAlign.center, underline: true),
      ),
    ]);

Print image:

import 'dart:io';
import 'package:image/image.dart';

const String filename = './logo.png';
final Image image = decodeImage(File(filename).readAsBytesSync());
// Using (ESC *) command
printer.printImage(image);
// Using an alternative obsolette (GS v 0) command
printer.printImageRaster(image);

Print barcode:

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

TODO #

  • Add raw print function
  • Print images
  • Print barcodes
  • Print QR codes
  • Turn 90° clockwise rotation mode on/off
  • Flutter example: discover active Wi-Fi printers
  • USB printers support
  • Add encoding commands

Test print #

test receipt

[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 'package:esc_pos_printer/esc_pos_printer.dart';
import 'package:image/image.dart';

void main() {
  // To discover existing printers in your subnet, consider using
  // ping_discover_network package (https://pub.dev/packages/ping_discover_network).
  // Note that most of ESC/POS printers by default listen on port 9100.
  Printer.connect('192.168.0.123', port: 9100).then((printer) {
    printer.println(
        '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');
    printer.println('Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ',
        styles: PosStyles(codeTable: PosCodeTable.westEur));
    printer.println('Special 2: blåbærgrød',
        styles: PosStyles(codeTable: PosCodeTable.westEur));

    printer.println('Bold text', styles: PosStyles(bold: true));
    printer.println('Reverse text', styles: PosStyles(reverse: true));
    printer.println('Underlined text',
        styles: PosStyles(underline: true), linesAfter: 1);
    printer.println('Align left', styles: PosStyles(align: PosTextAlign.left));
    printer.println('Align center',
        styles: PosStyles(align: PosTextAlign.center));
    printer.println('Align right',
        styles: PosStyles(align: PosTextAlign.right), linesAfter: 1);
    printer.printRow([
      PosColumn(
        text: 'col3',
        width: 3,
        styles: PosStyles(align: PosTextAlign.center, underline: true),
      ),
      PosColumn(
        text: 'col6',
        width: 6,
        styles: PosStyles(align: PosTextAlign.center, underline: true),
      ),
      PosColumn(
        text: 'col3',
        width: 3,
        styles: PosStyles(align: PosTextAlign.center, underline: true),
      ),
    ]);
    printer.println('Text size 200%',
        styles: PosStyles(
          height: PosTextSize.size2,
          width: PosTextSize.size2,
        ));

    // Print image
    const String filename = './logo.png';
    final Image image = decodeImage(File(filename).readAsBytesSync());
    printer.printImage(image);
    // Print image using an alternative (obsolette) command
    // printer.printImageRaster(image);

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

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

    printer.cut();
    printer.disconnect();
  });
}

Use this package as a library

1. Depend on it

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


dependencies:
  esc_pos_printer: ^1.5.0

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]
85
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]
93
Learn more about scoring.

We analyzed this package on Nov 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
gbk_codec ^0.3.1+3 0.3.1+3
hex ^0.1.2 0.1.2
image ^2.1.4 2.1.9
Transitive dependencies
archive 2.0.11
args 1.5.2
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
html 0.14.0+3
meta 1.1.7 1.1.8
path 1.6.4
petitparser 2.4.0
sky_engine 0.0.99
source_span 1.5.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
xml 3.5.0
Dev dependencies
flutter_test