【问题标题】:How to display Hindi or Gujarati Font using Bluetooth Printer?如何使用蓝牙打印机显示印地语或古吉拉特语字体?
【发布时间】:2016-04-15 11:31:12
【问题描述】:

我正在使用Android-Bluetooth-Printer。如果我在edittext 中输入英文文本,它可以正常工作,但问题是如果我从软键盘选择印地语,然后我输入一些印地文并尝试打印,但它在纸上不显示任何内容。

public class BlueToothPrinterApp extends Activity       
{       

    EditText message;
    Button printbtn;

    byte FONT_TYPE;
    private static BluetoothSocket btsocket;
    private static OutputStream btoutputstream;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        message = (EditText)findViewById(R.id.message);
        printbtn = (Button)findViewById(R.id.printButton);

        printbtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                connect();
            }
        });
    }

    protected void connect() {
        if(btsocket == null){
            Intent BTIntent = new Intent(getApplicationContext(), BTDeviceList.class);
            this.startActivityForResult(BTIntent, BTDeviceList.REQUEST_CONNECT_BT);
        }
        else{

            OutputStream opstream = null;
            try {
                opstream = btsocket.getOutputStream();
            } catch (IOException e) { 
                e.printStackTrace();
            }
            btoutputstream = opstream;
            print_bt();

        }

    }


    private void print_bt() {
        try {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            btoutputstream = btsocket.getOutputStream();

            byte[] printformat = { 0x1B, 0x21, FONT_TYPE };
            btoutputstream.write(printformat);
            String msg = message.getText().toString();
            btoutputstream.write(msg.getBytes());
            btoutputstream.write(0x0D);
            btoutputstream.write(0x0D);
            btoutputstream.write(0x0D);
            btoutputstream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            if(btsocket!= null){
                btoutputstream.close();
                btsocket.close();
                btsocket = null;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try {
            btsocket = BTDeviceList.getSocket();
            if(btsocket != null){
                print_bt();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }  
}         

谁能帮我解决这个问题?

【问题讨论】:

  • 你做到了吗。我也需要同样的事情。
  • @Murali 是的,请尝试给出的答案
  • 我尝试了图像打印。但打印机陷入堆栈溢出。如果可能,可以发布您的工作代码。

标签: android printing android-bluetooth


【解决方案1】:

打印机内置了预定义的字符集。这些字符集称为code pages

您的蓝牙打印机与大多数 POS 打印机一样似乎不支持 Unicode。

要解决此问题,您可以尝试将输出转换为图像,然后使用打印机理解的仿真将其作为字节发送到打印机。(PCL、ESC/POS、ZPL 等)

【讨论】:

    猜你喜欢
    • 2020-10-25
    • 2014-02-23
    • 1970-01-01
    • 2019-05-06
    • 2012-01-28
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    • 2012-12-12
    相关资源
    最近更新 更多