andresperezmelo / print_bluetooth_thermal

Plugin para enviar bytes sin procesar a la impresora solo por ahora para Android
Other
27 stars 36 forks source link

Not Supporting Arabic #49

Open nadeer12 opened 4 months ago

andresperezmelo commented 3 months ago

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.

daravichit commented 3 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] bOE67

meharunnisa429 commented 2 months ago

Future createArabicTextImage(String text) async { final recorder = ui.PictureRecorder(); final canvas = Canvas(recorder); // final paint = Paint()..color = Colors.black; const textStyle = TextStyle( color: Colors.pink, fontSize: 28, fontWeight: FontWeight.bold, fontFamily: 'NotoSansArabic', );

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); }

daravichit commented 2 months ago

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