Search code examples
flutterdartprintingbluetooththermal-printer

How to print images using Flutter and a Thermal Bluetooth Printer


I have a "sales receipt" screen, so I need to print this using a bluetooth thermal printer, but when I try to print an image, I just receive a "black" square printed.

Print result (the image is just a logo with no background, so I tried with different pictures too, but no success)

Printed image as a black square

Code using blue_thermal_printer package (I tried with other packages but I had the same result)

printContent(BluetoothDevice device) async {
  await connectToPrinter(device);

  final imageBytes = await imagePathToUint8List('assets/images/logo_ps.png');
  await bluetooth.printImageBytes(imageBytes);
  await bluetooth.paperCut();

  await disconnectToPrinter();
}

Future<Uint8List> imagePathToUint8List(String path) async {
//converting to Uint8List to pass to printer

  ByteData data = await rootBundle.load(path);
  Uint8List imageBytes =
    data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
  return imageBytes;
}

Please, can someone tell me what I'm doing wrong?


Solution

  • My mistake was use a png "without background" to print using a thermal printer. When I used an image with a white background it worked.