首先,你打印测试页,查看打印机默认支持哪种字符集,我这里写的是cp936
然后参照下表
https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html
打印模块,用的是
https://github.com/DantSu/ESCPOS-ThermalPrinter-Android
下载aar引用
https://jitpack.io/com/github/anggastudio/Printama/0.9.7/Printama-0.9.7.aar
全部引用
implementation fileTree(dir: 'libs', include: ['*.aar'])
或者指定引用
implementation files('libs/Printama-0.9.7.aar')
打印代码示例
public void printMe() throws EscPosConnectionException, EscPosParserException, EscPosEncodingException, EscPosBarcodeException {
//gb18030 or cp936 简体中文 cp932 日文
BluetoothConnection printerConn=BluetoothPrintersConnections.selectFirstPaired();
EscPosPrinter printer = new EscPosPrinter(printerConn,
203,
48f,
32,
new EscPosCharsetEncoding("cp936", 0));
printer.printFormattedText(
//"[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer, App.getContext().getApplicationContext().getResources().getDrawableForDensity(R.drawable.ic_launcher_foreground, DisplayMetrics.DENSITY_MEDIUM))+"</img>\n" +
//"[L]\n" +
"[C]<u><font size='big'>ORDER N°045</font></u>\n" +
"[L]\n" +
"[C]========你说什么哈=========\n" +
"[L]\n" +
"[L]<b>BEAUTIFUL SHIRT</b>[R]9.99e\n" +
"[L] + Size : S\n" +
"[L]\n" +
"[L]<b>AWESOME HAT</b>[R]24.99e\n" +
"[L] + Size : 57/58\n" +
"[L]\n" +
"[C]--------------------------------\n" +
"[R]TOTAL PRICE :[R]34.98e\n" +
"[R]TAX :[R]4.23e\n" +
"[L]\n" +
"[C]================================\n" +
"[L]\n" +
"[L]<font size='tall'>Customer :</font>\n" +
"[L]Raymond DUPONT\n" +
"[L]5 rue des girafes\n" +
"[L]31547 PERPETES\n" +
"[L]Tel : +33801201456\n" +
"[L]\n" +
"[C]<barcode type='ean13' height='10'>831254784551</barcode>\n"
);
}