3 Best Flutter Printer Libraries

These Flutter printer libraries will help making an app which allows document or receipt printing easier.

esc_pos_printer

ecs_pos_printer allows to print documents using an ESC/POS thermal WiFi/Ethernet printer.

import 'package:esc_pos_printer/esc_pos_printer.dart';

const PaperSize paper = PaperSize.mm80;
final profile = await CapabilityProfile.load();
final printer = NetworkPrinter(paper, profile);

final PosPrintResult res = await printer.connect('192.168.0.123', port: 9100);

if (res == PosPrintResult.success) {
  testReceipt(printer);
  printer.disconnect();
}

printing

printing can generate and print documents to Android or iOS compatible printers.

import 'package:pdf/widgets.dart' as pw;

final doc = pw.Document();
doc.addPage(pw.Page(
      pageFormat: PdfPageFormat.a4,
      build: (pw.Context context) {
        return pw.Center(
          child: pw.Text("My first printed text"),
        ); // Center
      })); // Page
//print with a TrueType font from a flutter bundle:
final font = await rootBundle.load("assets/open-sans.ttf");
final ttf = pw.Font.ttf(font);

doc.addPage(pw.Page(
    build: (pw.Context context) {
      return pw.Center(
        child: pw.Text('Dart is awesome', style: pw.TextStyle(font: ttf, fontSize: 40)),
      ); // Center
    })); // Page

flutter_sunmi_printer

This library allows to print thermal receipts using Sunmi device’s built-in printer. The developer tested and confirmed that it worked on Sunmi V2.

It supports printing of text with styles (bold, underline, align, font size), row containing up to 12 columns, image with alignment, separator, empty lines, bold, and underline.

import 'package:flutter_sunmi_printer/flutter_sunmi_printer.dart';

// Test regular text
SunmiPrinter.hr(); // prints a full width separator
SunmiPrinter.text(
    'Test Sunmi Printer',
    styles: SunmiStyles(align: SunmiAlign.center),
);
SunmiPrinter.hr();

// Test align
SunmiPrinter.text(
    'left',
    styles: SunmiStyles(bold: true, underline: true),
);
SunmiPrinter.text(
    'center',
    styles:
        SunmiStyles(bold: true, underline: true, align: SunmiAlign.center),
);
SunmiPrinter.text(
    'right',
    styles: SunmiStyles(bold: true, underline: true, align: SunmiAlign.right),
);

// Test text size
SunmiPrinter.text('Extra small text',
    styles: SunmiStyles(size: SunmiSize.xs));
SunmiPrinter.text('Medium text', styles: SunmiStyles(size: SunmiSize.md));
SunmiPrinter.text('Large text', styles: SunmiStyles(size: SunmiSize.lg));
SunmiPrinter.text('Extra large text',
    styles: SunmiStyles(size: SunmiSize.xl));

// Test row
SunmiPrinter.row(
    cols: [
        SunmiCol(text: 'col1', width: 4),
        SunmiCol(text: 'col2', width: 4, align: SunmiAlign.center),
        SunmiCol(text: 'col3', width: 4, align: SunmiAlign.right),
    ],
);

// Test image
ByteData bytes = await rootBundle.load('assets/rabbit_black.jpg');
final buffer = bytes.buffer;
final imgData = base64.encode(Uint8List.view(buffer));
SunmiPrinter.image(imgData);

SunmiPrinter.emptyLines(3);

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close