我从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);
}这在意大利语系统中工作得很好,但当我在客户的西班牙语打印机上打印时,结果就不一样了。
我的工作底稿:

在客户的打印机上打印:

我的打印机的协议和字符集与我的客户打印机相同。
哪里出了问题,我该如何修复它?
发布于 2021-11-12 17:41:55
我已经找到了一个可以帮助你的解决方案。当您发送一个字节时,您应该能找到打印机实际打印的字符是什么。
我在一台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());
}https://stackoverflow.com/questions/42248441
复制相似问题