bluetooth_print icon indicating copy to clipboard operation
bluetooth_print copied to clipboard

how to adjust the size of the image when printing

Open ebrahimmansur opened this issue 3 years ago • 1 comments

this is the output when calling the following code :

` final ByteData byteData = await rootBundle.load(LogoPaths.anis); final imageData = byteData.buffer .asUint8List(byteData.offsetInBytes, byteData.lengthInBytes); String base64Image = base64Encode(imageData);

Map<String, dynamic> config = Map();
List<LineText> list = [];

list.add(LineText(
    type: LineText.TYPE_IMAGE,
    content: base64Image,
    align: LineText.ALIGN_CENTER,
    linefeed: 1));

bluetoothPrint.printReceipt(config, list);`

#output

IMG_20210620_151556

ebrahimmansur avatar Jun 20 '21 13:06 ebrahimmansur

edit bluetooth_print/android/src/main/java/com/example/bluetooth_print/PrintContent.java file,

change the below code to

else if("image".equals(type)){
        byte[] bytes = Base64.decode(content, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
        esc.addRastBitImage(bitmap, 576, 0);
  }

to

else if("image".equals(type)){
        byte[] bytes = Base64.decode(content, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
        esc.addRastBitImage(bitmap, width, 0);
  }

use this code flutter/dart program,

list.add(LineText(
        type: LineText.TYPE_IMAGE,
        content: base64Image,
        align: LineText.ALIGN_CENTER,
        width: 150,
        height: 150,// pass desired width
        size: 1,
        weight: 1,
        linefeed: 1));

for ios

edit bluetooth_print/ios/Classes/BluetoothPrintPlugin.m file change the below code to

else if([@"image" isEqualToString:type]){
            NSData *decodeData = [[NSData alloc] initWithBase64EncodedString:content options:0];
            UIImage *image = [UIImage imageWithData:decodeData];
            [command addBitmapwithX:[x intValue] withY:[y intValue] withMode:0 withWidth:480 withImage:image];
        }

to

else if([@"image" isEqualToString:type]){
            NSData *decodeData = [[NSData alloc] initWithBase64EncodedString:content options:0];
            UIImage *image = [UIImage imageWithData:decodeData];
            [command addBitmapwithX:[x intValue] withY:[y intValue] withMode:0 withWidth:YourWith withImage:image];
        }

UnluckyY1 avatar Jul 05 '21 17:07 UnluckyY1

@UnluckyY1 this solution still work on latest version or not ? i try it doesn't works

YouSour avatar Nov 15 '22 08:11 YouSour