Open nadeer12 opened 4 months ago
Same problem! I want to print khmer font (Unicode font) but maybe my printer not support this font so, I try your first solution
With android work properly but in ios print only 10% of it. I think the problem come from the height of image ( 655 px ). Any solutions with this case.
I has been try to short it to multi image but still the same
final profile = await CapabilityProfile.load();
final generator = Generator(PaperSize.mm58, profile);
List<int> bytes = [];
bytes += generator.reset();
var image = img.decodeImage(imageBytes);
int x = 0, y = 0;
int height = (image.height / 10).floor();
for (int i = 0; i < 10; i++) {
var byteString = Uint8List.fromList(img.encodeJpg( img.copyCrop(image, x : x, y: y, width : image.width, height:height) ));
var newImage = img.decodeImage(byteString);
bytes += generator.imageRaster( newImage!,align: PosAlign.center );
y += height;
}
PrintBluetoothThermal.writeBytes(bytes)
[sample photo]
Future
final textSpan = TextSpan(text: text, style: textStyle);
final textPainter = TextPainter(
text: textSpan,
textDirection: TextDirection.rtl,
);
textPainter.layout();
textPainter.paint(canvas, const Offset(0, 0));
final picture = recorder.endRecording();
final imgData = await picture.toImage(
textPainter.width.toInt(),
textPainter.height.toInt(),
);
final byteData = await imgData.toByteData(format: ui.ImageByteFormat.png);
return byteData!.buffer.asUint8List();
}
const arabictext = 'ق ك ل م ن ه و ي';
final arabicImageBytes = await createArabicTextImage(arabictext); log(arabicImageBytes.toString(), name: "arabic text"); final decodedImage = packageImg.decodeImage(arabicImageBytes); log(decodedImage.toString(), name: "decodedImage"); if (decodedImage != null) { final escPosImage = packageImg.Image.fromBytes( width: decodedImage.width, height: decodedImage.height, bytes: decodedImage.buffer, // decodedImage.getBytes(), ); log(escPosImage.toString(), name: "escPosImage"); bytes += ticket.image(decodedImage); }
Thank @meharunnisa429 for your support.
Finally I got the solution, the problem because of iOS device cannot sent large bytes to printer.
bytes += decodeImage // is not recommend
So we need to generate multi images and print multi times, make sure each image not bigger than 100kb
final profile = await CapabilityProfile.load();
final generator = Generator(PaperSize.mm58, profile);
for(int i = 0; i < canvasImageList.length ; i++){
Image image = canvasImageList[i];
var bytes = generator.image( image! );
PrintBluetoothThermal.writeBytes( bytes );
await Future.delayed(const Duration(seconds: 1));
PrintBluetoothThermal.writeBytes('\x1B@'.codeUnits);
}
It working as expected. But sometime they add space between each images
Some thermal printers, depending on their firmware and font support, may not properly handle Arabic characters directly from a package like flutter_esc_pos_utils. This is because:
Possible solutions:
I’m going to investigate this further.