generatePrintCmd static method
生成打印圖片指令 singleByteSizeLimit: 单次写入的长度限制
Implementation
static Future<List<List<int>>> generatePrintCmd({
String? imgPath,
Uint8List? imgData,
required PrintTypeEnum printType,
int imgSizeLimit = 550 * 1000,
}) async {
if (imgPath == null && imgData == null) {
throw Exception(
'generatePrintCmd error : imgPath and imgData cannot be empty at the same time');
}
Uint8List imgBytes;
if (imgData != null) {
imgBytes = imgData;
} else {
imgBytes = await ImageTool.getImage(imgPath!);
}
final cmdData = printType == PrintTypeEnum.receipt
? await ESCPrinterService(
imgBytes,
imgSizeLimit: imgSizeLimit,
).getBytes()
: await TscPrinterService(
imgBytes,
).getBytes();
return cmdData;
}