【问题标题】:ESC/POS raw print -á, -é, -í, -ó, -ú, -ü, -ñ, ¿, ¡ work locally ( Italy ) but not in SpainESC/POS 原始打印 -á, -é, -í, -ó, -ú, -ü, -ñ, ¿, ¡ 在本地(意大利)工作,但不在西班牙工作
【发布时间】:2017-07-04 01:24:17
【问题描述】:

我从 Web 服务收到一个字符串,我想在 ESC/POS 打印机上打印它。我试过这个:

private void print()
{
    PrintService ps = getPrinter(deviceSystemName);
    byte[] commandByteArray = decodeReceiptCommandString();
    DocFlavor df = DocFlavor.INPUT_STREAM.AUTOSENSE;
    ByteArrayInputStream pis = new ByteArrayInputStream(commandByteArray);

    Doc d = new SimpleDoc(pis, df, null);
    if (ps != null) {
        DocPrintJob job = ps.createPrintJob();
        job.print(d, null); 
    }
}

private byte[] decodeReceiptCommandString()
{
    String encoding = "Cp850";
    String commandString = new String(this.receipt.getString("stringa"));
    return commandString.getBytes(encoding);
}

这在意大利系统中运行良好,但是当我在客户的西班牙打印机上打印时,结果就不一样了。

我的工作打印:

在我客户的打印机上打印:

我的打印机的协议和字符集与我的客户打印机相同。

出了什么问题,我该如何解决?

【问题讨论】:

  • 什么是this.receipt.getString("stringa"),它是如何初始化的,它来自哪里?如果它已经是一个字符串,那么在它上面使用new String() 是没有意义的。如果它来自某个配置文件,请确保使用正确的编码读取文件。
  • this.receipt 是 JSONObject,我必须用 .getString(key) 获取内容,key 是收据 JSONObject 收据结构 = { id : int , stringa:String };
  • 那么你有没有在打印前检查过这个字符串没有被破坏?我的猜测是问题可能出在其他地方......
  • 您是否确保将打印机设置为与您发送给它的数据相同的代码页?要设置代码页 850,请将 ESC t 0x02 发送到打印机。
  • 您使用的是什么打印机(品牌、型号)?

标签: java character-encoding epson escpos


【解决方案1】:

我找到了一个可以提供帮助的解决方案。您应该找到您的打印机在发送字节时实际打印的字符是什么。

我在 ESC POS HASAR 180 打印机上对此进行了测试,发现字符顺序非常奇怪,根本没有标准。

这是我的代码:

static byte[] PrintChars() {
    StringBuilder sb = new StringBuilder();
    for (int i = 33; i < 256; i++)
    {
        sb.Append((char)i + "-");
    }
    sb.Append("\n");
    return Encoding.UTF8.GetBytes(sb.ToString());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-15
    • 2014-12-27
    • 2014-11-30
    • 2012-07-14
    • 2019-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多