SALMAN ABOHOLIQAH
SALMAN ABOHOLIQAH

Reputation: 79

How to print Arabic string in Bluetooth printer using flutter

I want to print a receipt voucher in Arabic, but after printing the words appear in Chinese. I'm using esc_pos_bluetooth package to print via Bluetooth and I followed the steps in package example here . this is the code to print:

Future<Ticket> getReceipt(PaperSize paper) async {
    final Ticket ticket = Ticket(paper);

    Uint8List encArabic =
        await CharsetConverter.encode("windows-1256", "اهلا");

    print("encArabic:$encArabic");
    ticket.textEncoded(encArabic,
        styles: PosStyles(codeTable: PosCodeTable.pc864_1));

    final now = DateTime.now();
    final formatter = DateFormat('MM/dd/yyyy H:m');
    final String timestamp = formatter.format(now);
    ticket.text(timestamp,
        styles: PosStyles(align: PosAlign.center), linesAfter: 2);
    ticket.cut();
    return ticket;
  }

The word "اهلا" should be printed in Arabic but it appears in Chinese. For the printer that I'm using it was from an unknown company the only thing I knew about it was the model: MHT-29L

Upvotes: 1

Views: 2555

Answers (1)

Elrayes
Elrayes

Reputation: 21

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.

a picture of what they said in the documentation

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
]));

Upvotes: 2

Related Questions