admin管理员组

文章数量:1123150

I'm facing an issue while trying to print the Euro symbol (€) on my thermal receipt using a Bluetooth thermal printer and the /documentation/bluetooth_print/latest/ package in Flutter.

What I’m using: Flutter package: bluetooth_print Printer type: Thermal Bluetooth printer Encoding: I’ve tried using ISO-8859-15 (Latin-9) to include the Euro (€) symbol. The Problem: Whenever I print a line containing the Euro symbol (€), the printer outputs strange characters (for example, a 1 or a garbled symbol). Below is a sample of my current code:

List<int> encodeToLatin9(String input) {
  const latin9Table = {
    '€': 0xA4, // Euro sign in ISO-8859-15
  };

  List<int> encodedBytes = [];
  for (var char in input.runes) {
    if (char < 128) {
      encodedBytes.add(char);
    } else if (latin9Table.containsKey(String.fromCharCode(char))) {
      encodedBytes.add(latin9Table[String.fromCharCode(char)]!);
    } else {
      encodedBytes.add(0x3F); // Replace with '?' if character not found
    }
  }
  return encodedBytes;
}

List<LineText> list = [];
list.add(LineText(
  type: LineText.TYPE_TEXT,
  content: String.fromCharCodes(encodeToLatin9('Total price: 20.00 €')),
  align: LineText.ALIGN_CENTER,
));

What I’ve Tried So Far: Using UTF-8 Encoding: I tried:

utf8.encode('Total price: 20.00 €');
Result: The Euro symbol (€) is still displayed incorrectly.

Using Unicode Escape Code (\u20AC): I tried:

'Total price: 20.00 \u20AC';

Result: The output is still incorrect.

Replaced Euro Symbol with Alternative Text: I replaced € with "EUR", which worked fine, but it’s not ideal.

Tested with Another Thermal Printer: I tested another printer, but the problem persists.

Here a image:

本文标签: Unable to print the Euro € symbol on a receipt using the Flutter bluetoothprint packageStack Overflow