I’m facing an issue while trying to print the Euro symbol (€) on my thermal receipt using a Bluetooth thermal printer and the https://pub.dev/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.
2
Answers
You can use
u{20AC}
.However in most of edge-cases I use bitmap converter to make each character a bitmap image. and then print that.
I used for logo as well as to print our local currency-format.
and when I use this on ui/printing side,
I just call like,
PS: It might seems overkill to do this simple task. But in certain edge cases, it’ll work.
To print the Euro symbol (€) on a thermal receipt using the
bluetooth_print
package in Flutter, follow these steps:1. Check Printer’s Supported Encoding
2. Set the Printer’s Encoding
3. Encode Your Text
Map the Euro symbol (€) to the correct encoding value. For Windows-1252, it’s
0x80
:Use the encoded text when printing:
4. Test and Adjust
€
withEUR
as a fallback.This should help you print the Euro symbol correctly!