带热敏打印机的ESC / POS打印阿拉伯字符

时间:2019-04-30 11:02:27

标签: android printing

我正在尝试从android java在escpos中打印阿拉伯字符串。但是只打印一些汉字。我的打印机支持阿拉伯语。

这是我的代码

private void printArabic() throws IOException {
    String print ="الجحيم";

    ByteBuffer init = ByteBuffer.allocate(2);
    init.put((byte) 0x1B);
    init.put((byte) 0x25);
    sendData(init.array(), outputStream);

    ByteBuffer dataToPrint = ByteBuffer.allocate(print.length());
    dataToPrint.put(print.getBytes("cp864"));
    sendData(dataToPrint.array(), outputStream);


}
private void sendData(byte[] buffer, OutputStream os) throws IOException
{
    try {
        ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
        os.write(byteBuffer.array());
        os.flush();
        // tell the user data were sent

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

如果有人可以建议任何代码示例,这将很有帮助。

1 个答案:

答案 0 :(得分:1)

问候,

您的程序很棒,效果很好。

问题是传递给打印机的字符编码。 从程序到打印机的网络中的某个位置,UTF-8编码(java默认)将转换为其他编码。

检查打印机默认编码,可能可以更改。 如果无法更改默认打印机编码,请相应地更改java编码。

如果网络中有代理服务器/过滤器/防火墙,它也可能会更改编码。

更新

使用操作系统打印机的默认设置更改默认打印机编码。

更改已回答here的Java编码。

相关问题