when I try to send text content to my thermal printer it gives me the chinese symbols in case of Arabic and in case in English it give me the correct phrase
could you help me with this problem this is image that describe what I mean :
Hello Black Night - what font are you trying to use? A bespoke Arabic font or a Unicode font? Could it be that you need to load the font (True Type) into your App?
really I don't know cause this is my first time dealing with thermal printer but I use this printer "Xprinter XP-P810"
What I want is to print Arabic successfully as English text
.... looks like you can't. The method with an App Font produces an image of the document to be printed but it would seem images are not supported by the XP-P810.
However, Epson ESC/POS is supported. That may mean the XP-P810 supports Unicode - first thing to to do is ask the printer manufacturer if that is so, via the link above (message or chat).
Epson ESC/POS code:
Edit: Ask xprinter which ESC/POS commands are supported - even the Epson printers do not support all of them.
ABG - any ideas to output Arabic with this little printer? I was thinking of a Blocks List of the Arabic Unicode Character codes, build the document via a translation to code from Arabic Text in a Textbox set by the App User.
Most of them are unsuccessful, or have to resort to hacks like generating a bmp image and feeding its bytes to the printer after the code to switch to bmp mode.
Can AI2 print Arabic on a canvas?
Can that Canvas be exported as an image and converted to bmp format then be read back as bytes?
Probably need a JavaScript stunt for that.
Throw in the right to left print direction of Arabic cursive text.
Print extensions just gloss over code conversions.
Lots of luck asking the extension author for support.
I think we can do it without an extension. If the ESC/POS used by the printer accepts images, the document could be laid out on a Canvas, but probably easier to just use a TextBox if the document is something like a receipt. Even though the Arabic text is read right-to-left by the User, it doesn't matter that App Inventor will read it left-to-right (for conversion), it will still be correct on the document.
@ChrisWard The Xprinter XP-P810 supports generic ESC/POS commands, which are a set of commands for controlling the formatting and printing of thermal printers
I also made some web searching:
To print any language like Arabic, you need to do two things:
Set the correct character code table for the language you want to print. For Arabic, the code page is 2213, which is represented by 0x16 in hexadecimal. The ESC/POS command for setting the code page is ESC t n (ASCII) or 1B 74 n (Hex), where n is the code page number. So, to set the code page to 22, you need to send the command 1B 74 16 (Hex) to the printer.
Here is an example of how to print the Arabic text “شركة الحياة” on the Xprinter XP-P810 using Android Studio:
try {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.BLUETOOTH}, InvoiceActivity_AR.PERMISSION_BLUETOOTH);
} else {
BluetoothConnection connection = BluetoothPrintersConnections.selectFirstPaired();
if (connection != null) {
EscPosPrinter printer = new EscPosPrinter(connection, 203, 78f, 48);
// Set the code page to 22
final String codePage = new String(new byte[]{0x1B, 0x74, 0x16});
// Encode the text in Windows-1256
final String text = new String("شركة الحياة".getBytes("Windows-1256"));
// Print the text
printer.printFormattedText(codePage + text);
} else {
Toast.makeText(this, "No printer was connected!", Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
Log.e("APP", "Can't print", e);
}
But I still can't convert it to a Java function to send the command to the printer,
You can't assume the Xprinter supports all of the ESC/POS commands, you need to ask the manufacturer what it supports, which is likely to be a subset.
If the Xprinter supports Unicode via ESC/POS, you don't need the language code page nor Windows-125614 encoding, hence why I said chat with the Xprinter people.
Even if you do need to set the code page and Windows-125614 encoding, you do not need a Java function to send the commands to the printer, you can send using App Inventor's Bluetooth Classic or App Inventor's BLE extension - you need to know the version of Bluetooth that the printer uses.
I look at your code and you actually use utf 8 encoding because getBytes(); adopts the default encoding of the platform, in our case Android, where the standard is Utf8.
I'm wondering about this code: command.add((byte) charset.getBytes()[0]);
What is this "UTF-8".getByte()[0]; method supposed to return?