android - 如何在蓝牙 POS 打印机中打印右对齐的文本?
问题描述
我一直在尝试在 android 中做一个 POS 应用程序,我在连接到该应用程序的蓝牙打印机上打印收据。我可以使用设备随附的 HOINSDK 打印“大”、“小”和 QR 码,并且可以对齐“左”和“中心”,但无法将其与“右”对齐。任何帮助表示赞赏。
以下是各个事物的代码:
//For Large Text
cmd[0] = 27;
cmd[1] = 97;
cmd[2] &= 0xEF;
mService.write(cmd);
mService.sendMessage("" + large_txt.getText().toString(), "GBK");
//For Small Text
cmd[0] = 0x1b;
cmd[1] = 0x21;
cmd[2] &= 0xEF;
mService.write(cmd);
mService.sendMessage("" + small_txt.getText().toString(), "GBK");
//For Center Alignment small text
cmd[0] = 27;
cmd[1] = 97;
cmd[2] |= 1;
mService.write(cmd);
cmd[0] = 27;
cmd[1] = 97;
cmd[2] = 1;
mService.write(cmd);
mService.sendMessage("" + center_txt.getText().toString(), "GBK");
//For centre alignment Large Text
cmd[1] = 97;
cmd[2] |= 1;
mService.write(cmd);
cmd[0] = 0x1b;
cmd[1] = 0x21;
cmd[2] = 0x10;
mService.write(cmd);
mService.sendMessage("" + center_txt.getText().toString(), "GBK");
//For Left alignment
cmd[0] = 27;
cmd[1] = 97;
cmd[2] |= 1;
mService.write(cmd);
cmd[0] = 27;
cmd[1] = 97;
cmd[2] = 0;
mService.write(cmd);
mService.sendMessage("" + left_txt.getText().toString(), "GBK");
如果有人可以帮助我使用正确的对齐代码,那将会很有帮助。
解决方案
添加此打印机命令
public static final byte[] ESC_ALIGN_RIGHT = new byte[] { 0x1b, 'a', 0x02 };
推荐阅读
- html - 标题/部分粘贴到页面顶部
- postgresql - 当我有高度值属性时,如何将 2D OSM 多边形转换为 3D?
- robotframework - 重定向 uri-RequestLibarry-Robot 框架
- ios - Flutter:如何在IOS中创建后台服务
- html - 跨度 HTML 中的文本对齐
- r - 如何防止 R 自动调整绘图大小?
- python - 返回结果并引发异常的替代解决方案
- python - Pandas to_sql 对于宽表有错误:以“xxx”开头的标识符太长。最大长度为 128。 (103) (SQLExecDirectW)
- android - Google Play IAP 中目标用户的订阅折扣
- javascript - 在我用 php 中的 FILTER_SANITIZE_STRING 检查值后,我是否需要前端 js 中的 htmlspecialchars()