哪种是在热敏打印机中打印GB磅符号的正确方法?
我正在使用以下代码编写打印机:
String pound = "\u00a3";
opstream = BluetoothPrinter.btSocket.getOutputStream();
//Tried
outputStream.write(pound.getBytes(StandardCharsets.UTF_8));
//Tried
outputStream.write(pound.getBytes(Charset.forName("UTF-8")));
我也尝试过£。在热敏打印机中,有什么替代方案?
答案 0 :(得分:0)
请尝试这样做:
String pound = "£ 20.00";
outputStream.write(BitmapAsEuro(pound));
public byte[] BitmapAsEuro(String poundValue){
Bitmap image = Bitmap.createBitmap(600, 200, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(26);
paint.setColor(Color.BLACK);
paint.setTextSize(26);
paint.setFlags(Paint.EMBEDDED_BITMAP_TEXT_FLAG);
canvas.drawText(poundValue,0,60,paint);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
image.recycle();
return byteArray;
}
答案 1 :(得分:0)
例如,确实是00
A3
。在code-page 1252
或437
中。
要进行切换,请使用ESC t n
,其中n
等于16
,例如。用于代码页1252
。
选择字符代码表。
ASCII ESC t n
Hex. 1B 74 0F
Decimal 27 116 16
这应该将其编码为匹配的格式:
String gbp = "£";
byte[] b = gbp.getBytes(Charset.forName("Windows-1252"));
在每种情况下,输出b
应该是00
A3
,并且打印机需要知道它是哪个代码页。除非将打印机切换到带有£
的代码页,否则无论它用哪个值表示(除非是图形),它都不会打印£
。请参阅ESC/POS Mode Command Specifications,第4-47页。在unicode中,它也是U+00A3(打印机可能不支持)。
整个序列为:1B 74 0F
00 A3
并切换回默认代码页:1B 74 00
咨询您的打印机手册,它甚至支持其代码页(0F
可能也会有所不同)。
答案 2 :(得分:-1)
我找到了
字符串英镑=“€”;
字符串codeL =“ GBK”;
opstream = BluetoothPrinter.btSocket.getOutputStream();
outputStream.write(pound.getBytes(codeL));