fajfield_print

Print labels and receipts on any thermal printer, at any paper width, offline, from one template.

  • Any width: 58, 80, 104/110/112 mm, or any number of dots. No more "only 58 and 80 mm".
  • Any printer language: ESC/POS (receipt printers), TSPL (TSC and most cheap label printers), ZPL (Zebra).
  • Any language of text: with fajfield_print_flutter, Malayalam, Hindi, Tamil, Arabic and others print correctly, because everything is sent as a picture, not as printer fonts.
  • Templates, not code: design in the Fajfield designer, download the JSON, and print it. Change the layout without releasing a new app.
  • Receipts that grow: tables repeat per item, and everything below moves down.
  • Never in the dark: logs at every step, errors with a code and a hint, a debug preview, a printer check and a test page.

Malayalam receipt, 80 mm GST invoice on a 110 mm printer 50 x 25 mm product label

Samples, templates and docs: fajfield.com/developers/flutter · Design receipts visually in the Fajfield designer, then Print / Export → For developers → Download template.

final printer = FajPrinter.network('192.168.1.50', paper: Paper.mm110);
final template = PrintTemplate.fromJsonString(jsonFromDesigner);
await printer.print(template, data: {'shop': 'Fresh Mart', 'items': items, 'total': '310.00'});

In Flutter, add fajfield_print_flutter and pass text: FlutterTextRenderer() to get real fonts.

Connecting

Printer on Code
Wi-Fi / LAN FajPrinter.network('192.168.1.50') (port 9100; set port: if different)
Bluetooth / USB FajPrinter.custom((bytes) => yourPlugin.write(bytes)): one line with any plugin
A file (.prn) FajPrinter.file('label.prn')
Nothing (testing) FajPrinter.dryRun()

Find printers on the network: await discoverPrinters() returns every device answering on port 9100.

Bluetooth tip: many Bluetooth printers lose data sent in one big write. Send in chunks:

FajPrinter.custom((b) => characteristic.write(b, withoutResponse: true),
    name: 'BT TVS RP3200', chunkSize: 180, chunkDelay: const Duration(milliseconds: 20));

Pick the language: language: PrinterLanguage.escpos (default), .tspl or .zpl.

Paper width

Paper.mm58      // 384 dots
Paper.mm80      // 576 dots
Paper.mm110     // 832 dots (also mm104, mm112)
Paper.mm(100)   // any width in mm
Paper.dots(800) // exact printable dots from the spec sheet

Not sure how wide your printer really prints? await printer.print(printer.testPage()) prints a mm ruler across the full width. Wherever the ruler stops is your real width.

Debugging: what happened and why

1. Logs. Every step (render, encode, connect, send, status) is logged with timings.

final log = PrintLogger.console(LogLevel.debug);       // print everything
final log = PrintLogger(level: LogLevel.info, onLog: (e) => myCrashlytics.log('$e')); // send to your logger
FajPrinter.network('192.168.1.50', logger: log);
[fajfield 11:02:41.120 INFO  connect] connected host=192.168.1.50 port=9100 ms=38
[fajfield 11:02:41.301 WARN  template] No value for {{total}}
    → Add "total" to the data you pass to print(), or remove it from the template.
[fajfield 11:02:41.410 INFO  send] sent bytes=18422 ms=109 to=network 192.168.1.50:9100

2. Errors you can act on. Every PrintException has a code, a message and a hint:

code example hint
connectTimeout Printer off, or not on the same Wi-Fi. Print the self-test page to see its IP.
connectRefused Wrong port. Most use 9100; some use 9101, 6101 or 515.
hostUnreachable Phone is on mobile data or a guest Wi-Fi.
tooWide Template is 832 dots but paper is 576. Use the right Paper.
writeFailed Connection dropped. For Bluetooth use chunkSize.
barcodeInvalid EAN-13 needs 12 digits (the check digit is added).

3. Warnings that don't stop printing: missing {{fields}}, things off the edge of the paper, text cut short, bad barcode data. They're in job.warnings and in the log.

4. See it before you print.

final r = await printer.preview(template, data: data);
File('preview.png').writeAsBytesSync(r.preview(debug: true)); // red outline around every element

In Flutter: FajPreview(result: r, debug: true), or drop FajDebugPanel(job: job) on a debug screen to see the preview, warnings, full log and the first bytes sent.

5. The job report: print(job.report()) gives the printer, page size, bytes, render/encode/send times, warnings and log. Paste it into a bug report.

6. Printer check: print(await printer.diagnose(printTest: true))

Fajfield printer check: network 192.168.1.50:9100, escpos, 80mm
  connection: OK
  status:     out of paper
    → Fix the printer (paper, cover, pause button) and try again.

7. See the bytes: job.hex() shows hex and ASCII, and FajPrinter.file() saves exactly what would be sent.

Templates in code

final t = PrintTemplate.label(widthMm: 50, heightMm: 25)
  ..text('{{name}}', x: 10, y: 8, size: 28, bold: true)
  ..text('MRP ₹{{mrp}}', x: 10, y: 44, size: 24)
  ..barcode('{{sku}}', x: 10, y: 80, height: 70);

Elements: text, box, ellipse, line, barcode (code128, ean13, ean8, upca, code39, i2of5, gs1-128), qr, datamatrix, image, invert, table. Positions are in printer dots (8 dots = 1 mm at 203 dpi).

Status

0.1.0, first version. Tested on: add your printers here. Report issues with job.report() attached.

Libraries

fajfield_print
Design labels and receipts once, print them anywhere: any paper width (58, 80, 110 mm and more), ESC/POS, TSPL and ZPL printers, fully offline, with logs that explain what went wrong.