januslo / react-native-bluetooth-escpos-printer

React-Native plugin for the bluetooth ESC/POS & TSC printers.
MIT License
367 stars 425 forks source link

remove white space between images in the printPic method ?? #168

Open LeanPerez21 opened 3 years ago

LeanPerez21 commented 3 years ago

index

feras-merwas commented 2 years ago

@LeanPerez21 can you please share you code i am stuck I got blank when I print image

await BluetoothEscposPrinter.printPic(base64JpgLogo, { width: 40, left: 0, });

zhietan commented 2 years ago

same issue please help

elemanjan commented 1 year ago

android/src/main/java/cn/jystudio/bluetooth/escpos/RNBluetoothEscposPrinterModule.java

@ReactMethod
    public void printPic(String base64encodeStr, @Nullable  ReadableMap options) {
        int width = 0;
        int leftPadding = 0;
        if(options!=null){
            width = options.hasKey("width") ? options.getInt("width") : 0;
            leftPadding = options.hasKey("left")?options.getInt("left") : 0;
        }

        //cannot larger then devicesWith;
        if(width > deviceWidth || width == 0){
            width = deviceWidth;
        }

        byte[] bytes = Base64.decode(base64encodeStr, Base64.DEFAULT);
        Bitmap mBitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
        int nMode = 0;
        if (mBitmap != null) {
            /**
             * Parameters:
             * mBitmap  要打印的图片
             * nWidth   打印宽度(58和80)
             * nMode    打印模式
             * Returns: byte[]
             */
            byte[] data = PrintPicture.POS_PrintBMP(mBitmap, width, nMode, leftPadding);
            //  SendDataByte(buffer);
            sendDataByte(Command.ESC_Init);
            sendDataByte(Command.LF);
            sendDataByte(data);
            remove this line // sendDataByte(PrinterCommand.POS_Set_PrtAndFeedPaper(30));
            remove this line // sendDataByte(PrinterCommand.POS_Set_Cut(1));
            remove this line // sendDataByte(PrinterCommand.POS_Set_PrtInit());
        }
    }