PrinterHelper.SetMag(“1”, “1”);
PrinterHelper.SetBold(“0”);
PrinterHelper.InverseLine(“0”, “0”, “700”,
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
“0”, “100”);
PrinterHelper.Text(PrinterHelper.TEXT, “8”, “0”, “0”, “130”, “啦啦啦”);
PrinterHelper.Text(PrinterHelper.TEXT, “3”, “0”, “0”, “160”, “啦啦啦”);
PrinterHelper.Text(PrinterHelper.TEXT, “3”, “0”, “0”, “190”, “啦啦啦”);
PrinterHelper.PrintQR(PrinterHelper.BARCODE, “10”, “240”, “2”, “16”, “eyJxcl90eXBlIjoic3RhZmYiLCJvc19pZCI6Nn0=”);
PrinterHelper.Form();
PrinterHelper.Print();
}
} catch (Exception e) {
Log.e(TAG, “printCPCL: =======>553” + e.getMessage());
e.printStackTrace();
}
}
}
}).start();
}
相关的方法在厂家集成文档中都有详细的描述,我就不在这里做过多的赘述了。效果如下图:
佳博的话也一样,下面给出打印代码:
public void printSend(View view) {
threadPool = ThreadPool.getInstantiation();
threadPool.addTask(new Runnable() {
@Override
public void run() {
if (DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id] == null ||
!DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id].getConnState()) {
mHandler.obtainMessage(CONN_PRINTER).sendToTarget();
return;
}
if (DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id].getCurrentPrinterCommand() == PrinterCommand.TSC) {
sendLabel();
} else {
mHandler.obtainMessage(PRINTER_COMMAND_ERROR).sendToTarget();
}
}
});
}
void sendLabel() {
LabelCommand tsc = new LabelCommand();
/* 设置标签尺寸,按照实际尺寸设置 */
tsc.addSize(40, 30);
/* 设置标签间隙,按照实际尺寸设置,如果为无间隙纸则设置为0 */
tsc.addGap(2);
/* 设置打印方向 */
tsc.addDirection(LabelCommand.DIRECTION.FORWARD, LabelCommand.MIRROR.NORMAL);
/* 设置原点坐标 */
tsc.addReference(0, 0);
/* 撕纸模式开启 */
tsc.addTear(EscCommand.ENABLE.ON);
/* 清除打印缓冲区 */
tsc.addCls();
// 绘制简体中文
tsc.addText(10, 20, LabelCommand.FONTTYPE.SIMPLIFIED_CHINESE, LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,
“标准科室名称:药剂科”);
tsc.addText(10, 50, LabelCommand.FONTTYPE.SIMPLIFIED_CHINESE, LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,
“标准科室代码:wsd8965325”);
tsc.addText(10, 80, LabelCommand.FONTTYPE.SIMPLIFIED_CHINESE, LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,
“实际科室名称:药剂科”);
tsc.addText(10, 110, LabelCommand.FONTTYPE.SIMPLIFIED_CHINESE, LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,
“重量” + tv_weight.getText().toString().trim());
tsc.addQRCode(150, 150, LabelCommand.EEC.LEVEL_L, 4, LabelCommand.ROTATION.ROTATION_0, “12345ss67”);
/* 打印标签 */
tsc.addPrint(1, 1);
/* 打印标签后 蜂鸣器响 */
tsc.addSound(1, 100);
tsc.addCashdrwer(LabelCommand.FOOT.F5, 255, 255);
Vector datas = tsc.getCommand();
/* 发送数据 */
if (DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id] == null) {
Log.d(TAG, “sendLabel: 打印机为空”);
return;
}
DeviceConnFactoryManager.getDeviceConnFactoryManagers()[id].sendDataImmediately(datas);
}