3

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.

xSuperMu
  • 374
  • 2
  • 5
  • 16
  • I've tried to use 'CP720', 'ISO_8859-6', 'CP850' from here https://github.com/andrey-ushakov/esc_pos_utils/blob/master/lib/resources/capabilities.json and it prints non-arabic characters. – xSuperMu Feb 24 '21 at 17:10

3 Answers3

2

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.

1

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();
}
frankenapps
  • 5,800
  • 6
  • 28
  • 69
Foodlz
  • 19
  • 2
0

You have to find the character table for your printer and write the corresponding commands to let the printer know that you are printing multi byte characters such as Arabic characters. In my case, I was using sunmi printer and the only thing that worked for me was finding its character table and I wrote the commands and it worked very well. Here's a picture of what they said in the documentation. enter image description here

And this is what I did and it worked perfectly

const utf8Encoder = Utf8Encoder();
final encodedStr = utf8Encoder.convert(invoice.description);
bytes += generator.textEncoded(Uint8List.fromList([
  ...[0x1C, 0x26, 0x1C, 0x43, 0xFF],
  ...encodedStr
]));
Elrayes
  • 21
  • 3