0

i hvae used this amazing library ESCPOS ThermalPrinter Android to print recipt through thermal printer and it works fine but when it comes to add arabic words it never shows up here is my code `

private val usbReceiver = object : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {

        if (ACTION_USB_PERMISSION == intent.action) {
            synchronized(this) {

                if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                    usbDevice?.apply {
                            printer.printFormattedText(
                                "[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer, applicationContext.resources.getDrawableForDensity(R.drawable.logo, DisplayMetrics.DENSITY_MEDIUM)) +"</img>\n" +
                                        "[L]\n" +
                                        "[C]ريفلو\n" +
                                        "[C]جده - حي العزيزية\n" +
                                        "[C]<u>فاتورة ضريبية مبسطة</u>\n" +
                                        "[C]<u>Simplified Tax Invoice</u>\n" +
                                        "[L]<b>VAT Reg No.<b>[R]310473657600003[R]<b>رقم الضريبي<b>\n" +
                                        "[L]<b>Invoice No.<b>[R]AT0186[R]<b>رقم الفاتورة<b>\n" +
                                        "[L]<b>Date<b>[R]13-10-2022 11:05 AM [R]<b>تاريخ<b>\n" +
                                        "[L]\n" +

                                        "[C]--------------------------------\n" +

                                        "[L]\n" +
                                        "[L]<b>البيانـــــــــــات</b>[R]<b>كمية</b>[R]<b>سعر الوحده</b>[R]<b>ضريبة</b>[R]<b>الاجمالى</b>\n" +
                                        "[L]\n" +

                                        "[C]--------------------------------\n" +

                                        "[L]كوب كبير[R]1[R]21[R]2.74[R]21.00"+
                                        "[L]Large Cup"+
                                        "[L]\n" +
                                        "[L]كوب عادي[R]1[R]11[R]1.43[R]11.00"+
                                        "[L]Regular Cup"+
                                        "[L]\n" +
                                        "[L]كابتشينو[R]1[R]91[R]1.17[R]9.00"+
                                        "[L]Cappuccino"+
                                        "[L]\n" +
                                        "[L]حليب شوكلاته[R]1[R]12[R]1.57[R]12.00"+
                                        "[L]Milk Choc"+
                                        "[L]\n" +
                                        "[L]كوب عادي[R]1[R]11[R]1.43[R]11.00"+
                                        "[L]Regular Cup"+
                                        "[L]\n" +
                                        "[L]بسكويت اطفال[R]1[R]9[R]1.17[R]9.00"+
                                        "[L]Kids Cone"+
                                        "[L]\n" +
                                        "[L]كوب عادي فاخر[R]1[R]15[R]1.96[R]15.00"+
                                        "[L]Regular Cup Premium"+
                                        "[L]\n" +
                                        "[L]بسكويت فاخر[R]1[R]15[R]1.96[R]15.00"+
                                        "[L]Premium Cone"+
                                        "[L]\n" +

                                        "[C]--------------------------------\n" +

                                        "[L]\n" +
                                        "[L]قيمة المنتجــات[R][R][R][R]89.57"+
                                        "[L]Products Value ( Excl.VAT)"+
                                        "[L]\n" +
                                        "[L]خصم[R][R][R][R]0.00"+
                                        "[L]Discount(-)"+
                                        "[L]\n" +
                                        "[L]ضريبة القيمة المضافة[R][R][R][R]13.43"+
                                        "[L]VAT (15%)"+
                                        "[L]\n" +
                                        "[L]المجموع الكلي[R][R][R][R]103.00"+
                                        "[L]Grand Total"+
                                        "[L]\n" +
                                        "[L]Total 8 Items\n" +

                                        "[C]--------------------------------\n" +

                                        "[L] المبلغ المدفوع - نقدا[R][R][R][R]3.00"+
                                        "[L]Amount In Cash"+
                                        "[L]\n" +
                                        "[L]لمبلغ المدفوع - البطاقة[R][R][R][R]105.00"+
                                        "[L]Amount By Card "+
                                        "[L]\n" +
                                        "[L]الباقي[R][R][R][R]-5.00"+
                                        "[L]Balance "+
                                        "[L]\n" +
                                        "[C]<qrcode size='20'>http://www.developpeur-web.dantsu.com/</qrcode>\n"+
                                        "[C]****Thank You For Visit Come Again!****")
                    }
                }
                else {
                    Log.d(TAG, "permission denied for device $usbDevice")
                }
            }
        }
    }
}

fun printUsb(): View.OnClickListener? {

    val usbConnection = UsbPrintersConnections.selectFirstConnected(this)
    val usbManager = this.getSystemService(USB_SERVICE) as UsbManager

    if (usbConnection != null) {
        val permissionIntent = PendingIntent.getBroadcast(
            this,
            0,
            Intent(ACTION_USB_PERMISSION),
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0
        )

        val filter = IntentFilter(ACTION_USB_PERMISSION)
        registerReceiver(usbReceiver, filter)
        usbManager.requestPermission(usbConnection.device, permissionIntent)
    }
    return null
}

`

i have tried this one https://stackoverflow.com/a/73275372/13445734 but i don't know how to add it into my code

Barmge
  • 1
  • 1
  • Did you buy a printer that supports arabic? Most thermal printers have very limited character support, generally to latin letters. – Gabe Sechan Nov 12 '22 at 23:59

1 Answers1

0

You could try setting the encoding to one that handles Arabic script. I was going to suggest trying utf-8, but from the linked set of IDs that doesn't look like an option. Maybe try the PC720 one, ID 32?:

val printer = EscPosPrinter(deviceConnection, 203, 48f, 32, EscPosCharsetEncoding("pc720", 32));

I'm not sure exactly what name you should use, there are a few. I'm also not sure if you'd need to write your text in an editor with that encoding, and then paste it in - I'm just giving you stuff to look into really!

(The default is Windows-1252 which basically handles Latin script and doesn't have any Arabic characters)

cactustictacs
  • 17,935
  • 2
  • 14
  • 25