bluetooth_print icon indicating copy to clipboard operation
bluetooth_print copied to clipboard

can't print image latest version ^4.3.0

Open YouSour opened this issue 1 year ago • 8 comments

hi, i'm using latest version bluetooth_print: ^4.3.0, i can't print image

 OutlinedButton(
                        child: Text('print receipt(esc)'),
                        onPressed: _connected
                            ? () async {
                                Map<String, dynamic> config = Map();
                                List<LineText> list = [];

                                list.add(LineText(
                                  type: LineText.TYPE_TEXT,
                                  content: 'hi this is a test',
                                  weight: 1,
                                  align: LineText.ALIGN_CENTER,
                                ));
                        
                                ByteData data = await rootBundle
                                    .load("assets/images/bluetooth_print.png");
                                List<int> imageBytes = data.buffer.asUint8List(
                                    data.offsetInBytes, data.lengthInBytes);
                                String base64Image = base64Encode(imageBytes);
                                list.add(LineText(
                                    type: LineText.TYPE_IMAGE,
                                    content: base64Image,
                                    align: LineText.ALIGN_CENTER,
                                    linefeed: 1));
                                await bluetoothPrint.printReceipt(config, list);
                              }
                            : null,
                      ),

YouSour avatar Nov 02 '22 04:11 YouSour

Hi, i get the same error. is there any solution ?

ezraricad2 avatar Dec 02 '22 10:12 ezraricad2

@ezraricad2 i use this package https://pub.dev/packages/flutter_bluetooth_printer after no solution or reply

YouSour avatar Dec 03 '22 08:12 YouSour

hi i was facing the same error i resolved by adding height and width

list2.add(LineText(type: LineText.TYPE_IMAGE, content: base64Image, height: 90, width: 90, align: LineText.ALIGN_CENTER,));

fredwilliam avatar Dec 27 '22 01:12 fredwilliam

hi i was facing the same error i resolved by adding height and width

list2.add(LineText(type: LineText.TYPE_IMAGE, content: base64Image, height: 90, width: 90, align: LineText.ALIGN_CENTER,));

it works!!!!!

Elegalaxy avatar Jan 16 '23 08:01 Elegalaxy

Don't work in my case 😔 . I have the next code:

ByteData data = await rootBundle.load(ImageUtils.getImagePath("logo_ticket.png"));
List<int> imageBytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
String base64Image = base64Encode(imageBytes);

    header.add(LineText(
        type: LineText.TYPE_IMAGE,
        height: 350,
        width: 350,
        content: base64Image,
        align: LineText.ALIGN_CENTER));

javieritis avatar Jan 17 '23 11:01 javieritis

Don't work in my case 😔 . I have the next code:

ByteData data = await rootBundle.load(ImageUtils.getImagePath("logo_ticket.png"));
List<int> imageBytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
String base64Image = base64Encode(imageBytes);

    header.add(LineText(
        type: LineText.TYPE_IMAGE,
        height: 350,
        width: 350,
        content: base64Image,
        align: LineText.ALIGN_CENTER));

hi, try first to comment everything else and see if the image is printing. if it doesn't try to debug by setting break point before print or print in the console base64Image and see if there actually image to print.

Thanks

fredwilliam avatar Jan 17 '23 13:01 fredwilliam

try this one its worked for me. 
 List<LineText> list1 = [];
    ByteData data =
        await rootBundle.load("assets/static_images/ic-hmc-black.png");
    List<int> imageBytes =
        data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
    String base64Image = base64Encode(imageBytes);
    list1.add(LineText(
      type: LineText.TYPE_IMAGE,
      x: 10,
      y: 10,
      height: 200,
      width: 200,
      content: base64Image,
    ),
);

Zia9335 avatar Feb 01 '23 07:02 Zia9335

@Zia9335 Its working but position not start exactly to next label once first label done printing. Setting correct width and height with gap in labell configuration.

patelnirav48 avatar May 19 '23 09:05 patelnirav48