receiptline_dart 0.1.0
receiptline_dart: ^0.1.0 copied to clipboard
Pure Dart port of the ReceiptLine receipt description language. Renders receipt documents as plain text, SVG, or ESC/POS printer bytes.
ReceiptLine for Dart #
A pure-Dart implementation of the ReceiptLine receipt description language. It can render the same document as plain text or SVG, or generate ESC/POS bytes for a thermal printer. The package has no Flutter SDK dependency and works in Dart and Flutter applications, including Flutter web.
Features #
- ReceiptLine columns, magnetic alignment, wrapping, fixed/variable widths, rules, cuts, text decoration, embedded PNGs, raw commands, barcodes, and QR codes
- SVG output for Flutter previews and digital receipts
- Plain-text output for logs, tests, and accessible fallbacks
Uint8ListESC/POS output with PNG rasterization and native barcode/QR commands- CP437/852/858/860/863/865/866/1252, Shift-JIS, GBK, Korean, and Thai encoding
- A Dart
StreamTransformerfor chunked input
Install #
Until the package is published, reference this checkout from your app:
dependencies:
receiptline:
path: ../receiptline
Then run dart pub get or flutter pub get.
Render SVG #
import 'package:receiptline_dart/receiptline_dart.dart';
const document = '''
{align:center}
^^MY STORE
{align:left}
Coffee | 3.50
Cake | 4.25
---
^TOTAL | ^7.75
{option:qrcode,m,4}
{code:https://example.com/receipt/42}
''';
final svg = ReceiptLine.transform(
document,
const ReceiptLineOptions(cpl: 42),
);
In Flutter, render the returned string with flutter_svg:
SvgPicture.string(svg, fit: BoxFit.contain)
Generate printer bytes #
final bytes = ReceiptLine.transformBytes(
document,
const ReceiptLineOptions(
cpl: 42,
encoding: ReceiptLineEncoding.cp437,
command: ReceiptLineCommand.escPos,
cutting: true,
),
);
// Send bytes to the Bluetooth, USB, TCP, or platform printer API you use.
await printer.write(bytes);
Printer output is deliberately byte-oriented. This avoids the lossy "binary string" convention used by JavaScript printer libraries.
Other APIs #
final text = transform(
document,
const ReceiptLineOptions(command: ReceiptLineCommand.text),
);
final barcode = generateBarcode(
const ReceiptBarcode(data: '201234567890', type: 'ean', hri: true),
);
final qrMatrix = generateQrCode(
const ReceiptQrCode(data: 'hello', level: 'm', quietZone: true),
);
final output = await Stream.fromIterable(['Coffee | ', '3.50'])
.transform(ReceiptLine.createTransformer())
.single;
Compatibility #
The parser and text layout are ported from ReceiptLine 4.0.2. All official English and Japanese example documents have been compared with the upstream implementation; plain-text output is identical, and SVG dimensions match across the official English suite.
The current binary backend targets standard thermal ESC/POS. Upstream's specialized
Epson, SII, Citizen, Fujitsu, impact, StarPRNT, Star Line, and Star Graphic dialects
are not yet implemented. multilingual ESC/POS currently uses CP437, and CP950/Big5
printer-byte conversion falls back to CP437; SVG and text layout still support their
wide-character measurement. The backend interface is separated from the parser so
additional printer dialects can be added without changing ReceiptLine layout logic.
SVG output is semantically compatible rather than byte-identical: it uses a stable filter identifier and simplified vector junctions for ruled tables.
License #
Apache-2.0. This is a derivative port of ReceiptLine and retains its attribution in
NOTICE. QR Code is a registered trademark of DENSO WAVE INCORPORATED.