android - 如何设置蓝牙打印的字体大小?

标签 android printing bluetooth thermal-printer

I am writing an application which print ticket receipts.
I have some how written the code to print the receipt but the printer either      

以非常大的字体或非常小的(不可读)字体打印。 任何机构都可以为我提供设置格式的代码。

     try {
            //////////this code runs in thread
                    OutputStream os = mBluetoothSocket
                            .getOutputStream();
                    String BILL = "";
                    BILL = BILL
                            + "     *********      ";
                    BILL = BILL+"\n***Invoice No*** \n" +
                            "Muslim Movers\n"
                            +Todays_date+"\n";

                    BILL = BILL + "\n\n";
                    BILL = BILL + "Tickets:" + "      " + String.valueOf(tickets_wanted)+"\n";
                    BILL = BILL + "Price:        "+String.valueOf(Total_Tickets)+"\n"+
                            Selectedroute+"\n";
                    BILL = BILL
                            + "     *********     \n";
                    ////textsize and allignment
                    byte[] format = { 27, 33, 0 };
                    byte[] arrayOfByte1 = { 27, 3, 0 };
                    format[2] = ((byte)(0x10 | arrayOfByte1[2]));
                    format[2] = ((byte) (0x8 | arrayOfByte1[2]));
} catch (Exception e) {
                    Log.e("Main", "Exe ", e);
}
t.start();

最佳答案

Before writing change your printer configuration:

  byte[] cc = new byte[]{0x1B,0x21,0x00};  // 0- normal size text
  byte[] bb = new byte[]{0x1B,0x21,0x08};  // 1- only bold text
  byte[] bb2 = new byte[]{0x1B,0x21,0x20}; // 2- bold with medium text
  byte[] bb3 = new byte[]{0x1B,0x21,0x10}; // 3- bold with large text

  outputStream.write(cc);
  outputStream.write("Your String");

关于android - 如何设置蓝牙打印的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40815554/

相关文章:

android - 如何将外部库 jar 添加到 Android Studio 1.3 项目的 'External Libraries' 部分?

css - 打印时捕获整个 d3 图

html - 最后一页的页脚

替换 fragment 时未调用 Android onDetach()

java - HOUR_OF_DAY 的范围是多少?

java - Lollipop Bad WiFi 连接和回退到移动网络,如何检测?

javascript - 使用 MVC、JavaScript 显示弹出窗口

android - 通过蓝牙以编程方式从 Android 上的被动手持式打印机打印

macos - 如何通过 IOBluetooth 框架 (macOS) 获取 BLE 设备列表

Android BluetoothSocket.connect() 抛出 IOExceptions "Connection Refused"和 "Service discovery failed"