【问题标题】:Print Two Different Text Alignment on same line in Android Bluetooth thermal printer在 Android 蓝牙热敏打印机的同一行上打印两个不同的文本对齐方式
【发布时间】:2018-02-08 21:42:27
【问题描述】:

所以我们目前正在开发这个通过蓝牙打印收据的应用程序。该过程正在运行,但我们唯一的问题是我们无法打印我们想要的布局。

我们想以这种方式打印:

| ID Number:        123456789|

左边的字段是默认的,右边的字段是自动生成的。

我们尝试过解决问题,但蓝牙打印机似乎只读取一个文本对齐方式。

这是我们当前的代码:

 align=new byte[]{0x1B, 'a',0x00};     \\this is left alignment
 mmOutputStream.write(align);
 mmOutputStream.write(msg.getBytes());
 align=new byte[]{0x1B, 'a', 0x02};    \\this is right alignment
 mmOutputStream.write(align); 
 mmOutputStream.write(msg2.getBytes());

输出总是在顶部对齐。例如,当我们将顶部对齐设置在左侧时。它会像这样显示:

| ID Number:123456789        |

我希望你们能帮助我们,我们已经解决了大约一个星期。 谢谢! :)

【问题讨论】:

    标签: android printing bluetooth alignment


    【解决方案1】:

    我用这样的创建函数解决了这个问题:

    void writePrint(byte[] align, String msg){
        try {
            mmOutputStream.write(align);
            String space = "   ";
            int l = msg.length();
            if(l < 31){
                for(int x = 31-l; x >= 0; x--) {
                    space = space+" ";
                }
            }
            msg = msg.replace(" : ", space);
            mmOutputStream.write( msg.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    我们可以使用它:

    writePrint( PRINT_CENTER, "| ID Number : 123456789 |");
    

    【讨论】:

    • 这里的 31 是什么?
    • 31 是安卓设备的一行长度
    • 显示数字格式异常
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 2021-04-14
    • 2019-08-27
    • 2013-11-11
    • 2019-11-23
    • 2019-01-27
    • 2022-12-25
    相关资源
    最近更新 更多