Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print Arabic letters with thermal printer using Flutter esc_pos_printer library?

I'm using a printer: EPSON TM-m30

I'm currently using :

esc_pos_printer: ^4.0.3
esc_pos_utils: ^1.0.0

When I run this code

printDemoReceipt(NetworkPrinter printer) async {
    printer.text('ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ف ق ك ل م ن ه و ي');
    printer.feed(2);
    printer.cut();
    printer.disconnect();
}

It causes this error

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Invalid argument (string): Contains invalid characters.: "ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ف ق ك ل م ن ه و ي"
_UnicodeSubsetEncoder.convert  (dart:convert/ascii.dart:88:9)

Did anyone fix this issue?

Thank you.

like image 783
xSuperMu Avatar asked Oct 19 '25 13:10

xSuperMu


2 Answers

Actually I have the same issue and I believe for now the only solution is to create a PDF then covert it to an image and then you can print it.

like image 162
abdulrahman albeladi Avatar answered Oct 22 '25 03:10

abdulrahman albeladi


Try to

import 'dart:convert' show utf8;

printDemoReceipt(NetworkPrinter printer) async {

    final arabicText = utf8.encode('ا ب ت ث ج ح خ د ذ ر ز س ش ص ض ف ق ك ل م ن ه و ي');

    printer.textEncoded(arabicText);
    printer.feed(2);
    printer.cut();
    printer.disconnect();
}
like image 31
Foodlz Avatar answered Oct 22 '25 02:10

Foodlz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!