Skip to content

TinyGiantDigital/esc_pos_printer

 
 

Repository files navigation

esc_pos_printer

Printing Method.

There are two methods to print receipt.

  1. Using the widget method: The widget method generates an image from the flutter widget and prints generated images. This method is encouraged because it can print in an arbitrary format. For example, column, row, image, text in various languages, divider, underline, struck text, receipt border, QR code, and barcode. If we can render it on a device screen, then it can be printed. But the drawback is the print result on the dot matrix printer is not very good, see the table below. If the print quality for dot matrix printing is required, the developer needs to print using the text command
  2. Using text command method: Text commands rely on proper code table mapping, so you need to map the code table for the new printer correctly according to esc_pos_utils readme.md. Note: This method is a legacy method and should not be used if at all possible.

Quickstart

For full example usage, See example folder

General procedure is to

  1. Discover
PosPrinter.discover()
  1. Connect
PosPrinter.connect()
  1. Print widget
PosPrinter.widget()
  1. Cut
PosPrinter.cut()
  1. Pop drawer
PosPrinter.popDrawer()
  1. Transmit data to printer
PosPrinter.transmit()

API Reference

Function Prototype Return value
      PosPrinter.discover({bool onlyKnownProfile = true, PosPrinterInterface interface = PosPrinterInterface.All})
      
      Future<List<dynamic>>
      
  • Description: List discovered printer
  • Parameters:
    • onlyKnownProfile: true if you want to only discover printer that supported by the library
    • interface: POS printer inteface to discover

Function Prototype Return value
                PosPrinter.connect(dynamic printer,{String? networkPrinterProfile, required GlobalKey globalKey})
            
                Future<PosPrinterStatus>
            
  • Description: connect to the printer
  • Parameters:
    • printer: obtained from
      PosPrinter.discover()
    • networkPrinterProfile: required for EscPosNetworkPrinter, obtained from
      PosPrinter.availableProfile
    • globalKey: use for Widget image capturing. Application developer must pass the same globalKey in ReceiptWidget constructor like this
      ReceiptWidget(globalKey: globalKey,child: ReceiptData())

Function Prototype Return value
                PosPrinter.widget()
            
                Future
            
  • Description: print the ReceiptWidget that construct with the same globalKey used when connect with
    PosPrinter.connect()

Function Prototype Return value
                PosPrinter.cut({PosCutMode mode = PosCutMode.full})
            
                Future<Void>
            
  • Description: cut the paper
  • Parameters:
    • mode: cut mode. Only have two possibilities, partial cut and full cut

Function Prototype Return value
                PosPrinter.popDrawer()
            
                void
            
  • Description: pop the drawer

Function Prototype Return value
                PosPrinter.transmit()
            
                Future<PosPrinterStatus>
            
  • Description: transmit generated commands to connected printer

Implementation notes

  • An unsupported printer can be discovered by
// The library will load the default profile when connecting to an unsupported printer. So it will likely not work.
// Be aware that not only POS Printer will be discovered by this method.
// The return value will include other types of devices for that interface.
PosPrinter.discover(onlyKnownProfile: false)
  • For ESC/POS Network printer

    • Unlike other interface, Network interface cannot retrieve information from a printer, so the library cannot automatically load correct a profile. An application developer must prompt user to manually load a profile. See PosPrinter.connect() for more details.
  • For Star Micronics printer

    • This library should work gracefully with every Star Micronics printer model on every interface without a profile support, due to portability of StarPrnt SDK

Tested Printer.

For full list of verified tested printer, see capabilities.json

Model Type Paper Size Receipt Image
Xprinter XP-N160I Thermal Printer 80mm XP-N160I receipt image
Xprinter XP-58IIH Thermal Printer 58mm XP-58IIH receipt image
EPSON U02III Dot Matrix Printer 80mm
XPrinter-76 Dot Matrix Printer 80mm XP-76 receipt image
Star Micronics TSP100III Thermal Printer 80mm TSP100III receipt image

About

ESC/POS (thermal, receipt) printing for Flutter & Dart

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 94.9%
  • HTML 3.7%
  • Other 1.4%