パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.0.1

flutter_esc_pos_utils

このパッケージは、Bluetooth、WiFi/ネットワーク、またはUSBプリンタを使用して印刷するためのESC/POSコマンドを生成するために使用されます。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1.3万
いいね数
169
Pub ポイント
160

パッケージをインストール

flutter pub add flutter_esc_pos_utils

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

flutter_esc_pos_utils は、ブルートゥース、Wi-Fi/ネットワーク、またはUSBプリンターで印刷するためのESC/POSコマンドを生成するFlutterパッケージです。開発者がFlutterアプリからフォーマットされた印刷ジョブ(テキスト、バーコード、画像など)を互換性のあるレシートプリンターに送信できるようにします。このパッケージはAndroid、iOS、Web、macOS、Windows、Linuxなど複数のプラットフォームをサポートしており、クロスプラットフォームの販売ポイント(POS)アプリに最適です。低レベルのプリンターコマンドを使いやすいDartメソッドに抽象化することで、印刷可能なコンテンツを作成するプロセスを簡素化しています。

用途

  • 販売時点システム
  • 領収書印刷
  • ラベル印刷
  • 在庫管理
  • イベントチケットの印刷
  • 注文確認印刷

主な機能

  • ESC/POS コマンドを生成します
  • Bluetooth、Wi-Fi、USBプリンタをサポート
  • クロスプラットフォーム互換性
  • テキスト、バーコード、および画像印刷
  • 使いやすい API
  • 印刷形式オプション

適している対象

  • 小売POSアプリケーション
  • モバイル注文システム
  • 現場サービスレポート
  • レストランキオスク
  • 中小企業向けソフトウェア

注意事項

  • 互換性のあるESC/POSプリンタが必要です
  • プリンタ固有の癖が出力に影響を与える可能性があります
  • 高度なプリンタ機能に対するサポートが限定的
  • Wi-Fiプリンターのネットワーク設定が必要です
  • モバイルデバイスのBluetooth接続が必要です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

esc_pos_utils

Base Flutter/Dart classes for ESC/POS printing. Generator class generates ESC/POS commands that can be sent to a thermal printer.

This is the "base" library that used for:

Main Features

  • Connect to Wi-Fi / Ethernet printers
  • Simple text printing using text method
  • Tables printing using row 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), CODE128
  • Paper cut (partial, full)
  • Beeping (with different duration)
  • Paper feed, reverse feed

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

Generate a Ticket

Simple ticket with styles:
List<int> testTicket() {
  final List<int> bytes = [];
  // Using default profile
  final profile = await CapabilityProfile.load();
  final generator = Generator(PaperSize.mm80, profile);
  List<int> bytes = [];

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

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

  bytes += generator.text('Text size 200%',
      styles: PosStyles(
        height: PosTextSize.size2,
        width: PosTextSize.size2,
      ));

  bytes += generator.feed(2);
  bytes += generator.cut();
  return bytes;
}
Print a table row:
generator.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),
    ),
  ]);
Print an image:

This package implements 3 ESC/POS functions:

  • ESC * - print in column format
  • GS v 0 - print in bit raster format (obsolete)
  • GS ( L - print in bit raster format

Note that your printer may support only some of the above functions.

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

final ByteData data = await rootBundle.load('assets/logo.png');
final Uint8List bytes = data.buffer.asUint8List();
final Image image = decodeImage(bytes);
// Using `ESC *`
generator.image(image);
// Using `GS v 0` (obsolete)
generator.imageRaster(image);
// Using `GS ( L`
generator.imageRaster(image, imageFn: PosImageFn.graphics);
Print a Barcode:
final List<int> barData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 4];
generator.barcode(Barcode.upcA(barData));
Print a QR Code:

Using native ESC/POS commands:

generator.qrcode('example.com');

To print a QR Code as an image (if your printer doesn't support native commands), add qr_flutter and path_provider as a dependency in your pubspec.yaml file.

String qrData = "google.com";
const double qrSize = 200;
try {
  final uiImg = await QrPainter(
    data: qrData,
    version: QrVersions.auto,
    gapless: false,
  ).toImageData(qrSize);
  final dir = await getTemporaryDirectory();
  final pathName = '${dir.path}/qr_tmp.png';
  final qrFile = File(pathName);
  final imgFile = await qrFile.writeAsBytes(uiImg.buffer.asUint8List());
  final img = decodeImage(imgFile.readAsBytesSync());

  generator.image(img);
} catch (e) {
  print(e);
}

Using Code Tables

Different 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:

// Xprinter XP-N160I
final profile = await CapabilityProfile.load('XP-N160I');
final generator = Generator(PaperSize.mm80, profile);
bytes += generator.setGlobalCodeTable('CP1252');

All available profiles can be retrieved by calling :

final profiles = await CapabilityProfile.getAvailableProfiles();

How to Help

  • Add a CapabilityProfile to support your printer's model. A new profile should be added to lib/resources/capabilities.json file
  • Test and report bugs
  • Share your ideas about what could be improved (code optimization, new features...)

カテゴリー

依存関係

依存関係一覧 3 件

ソースリポジトリ

このパッケージを使用しているプロジェクト