Surile / react-native-sunmi-printer

商米内置打印机
MIT License
47 stars 32 forks source link

How to print Image ? #1

Closed panhavey closed 2 years ago

Surile commented 2 years ago

image

panhavey commented 2 years ago

image

I didn't see you list it down. Do I need to use it as NativeModule?

Surile commented 2 years ago

I didn't see you list it down. Do I need to use it as NativeModule?

I don't have to. I forgot to list it

panhavey commented 2 years ago

I didn't see you list it down. Do I need to use it as NativeModule?

I don't have to. I forgot to list it

It shows error : Property 'printBitmap'Custom does not exist on type 'SunmiPrinterType'.

Surile commented 2 years ago

I didn't see you list it down. Do I need to use it as NativeModule?

I don't have to. I forgot to list it

It shows error : Property 'printBitmap'Custom does not exist on type 'SunmiPrinterType'.

hold on

panhavey commented 2 years ago

I didn't see you list it down. Do I need to use it as NativeModule?

I don't have to. I forgot to list it

It shows error : Property 'printBitmap'Custom does not exist on type 'SunmiPrinterType'.

hold on

If you working on it please also check SunmiScan, it doesn't return result.

Surile commented 2 years ago

I didn't see you list it down. Do I need to use it as NativeModule?

I don't have to. I forgot to list it

It shows error : Property 'printBitmap'Custom does not exist on type 'SunmiPrinterType'.

hold on

If you working on it please also check SunmiScan, it doesn't return result.

ok

Surile commented 2 years ago

Ok, you can use it now

panhavey commented 2 years ago

Ok, you can use it now

It got error : 'Got unknown argument class: Bitmap'

mikgross commented 2 years ago

+1 also getting 'Got unknown argument class: Bitmap'

Surile commented 2 years ago

+1 also getting 'Got unknown argument class: Bitmap'

Sorry, I am currently working from home and cannot debug.

Surile commented 2 years ago

@mikgross printBitmap,There is one more, you can try

mikgross commented 2 years ago

I tried

import cheekin from './../assets/printerImages/cheekin.bmp';
var printImage = Image.resolveAssetSource(cheekin).uri;
SunmiPrinter.printBitmap(printImage)

&&

import cheekin from './../assets/printerImages/cheekin.bmp';
var printImage = Image.resolveAssetSource(cheekin).uri;
SunmiPrinter.printBitmapCustom(printImage)

None work, any idea what I should do? Can you include a working example in the example app?

mikgross commented 2 years ago

Unfortunately the printing for images is not working. I have additionally tried to modify your package with a base64 string implementation then decoded as bitmap, it does not print. Do you have a working example?

Le mar. 5 avr. 2022 à 06:39, 夜雨 @.***> a écrit :

@mikgross https://github.com/mikgross printBitmap ,There is one more, you can try

— Reply to this email directly, view it on GitHub https://github.com/Surile/react-native-sunmi-printer/issues/1#issuecomment-1088260998, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIWEOLKHUY35KP6A3MGEH43VDO7XRANCNFSM5IFZFBDA . You are receiving this because you were mentioned.Message ID: @.***>

Surile commented 2 years ago

@mikgross There may be a problem with the api

mikgross commented 2 years ago

I have changed the Bitmap format to base64 string in the main input. and changed the handler as such:

public void printBitmap(String encodedString, Int pixelWidth) throws RemoteException {
    final String pureBase64Encoded = encodedString.substring(encodedString.indexOf(",")  + 1);
    final byte[] decodedBytes = Base64.decode(pureBase64Encoded, Base64.DEFAULT);
    Bitmap decodedBitmap = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
    int w = decodedBitmap.getWidth();
    Integer h = decodedBitmap.getHeight();
    Bitmap scaledImage = Bitmap.createScaledBitmap(decodedBitmap, pixelWidth, (pixelWidth / w) * h, false);
    printerService.printBitmap(scaledImage, innerResultCallback);
  }

Works fine. Do you want me to do a pull request?

SVPetrenko commented 2 years ago

I have changed the Bitmap format to base64 string in the main input. and changed the handler as such:

public void printBitmap(String encodedString, Int pixelWidth) throws RemoteException {
    final String pureBase64Encoded = encodedString.substring(encodedString.indexOf(",")  + 1);
    final byte[] decodedBytes = Base64.decode(pureBase64Encoded, Base64.DEFAULT);
    Bitmap decodedBitmap = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
    int w = decodedBitmap.getWidth();
    Integer h = decodedBitmap.getHeight();
    Bitmap scaledImage = Bitmap.createScaledBitmap(decodedBitmap, pixelWidth, (pixelWidth / w) * h, false);
    printerService.printBitmap(scaledImage, innerResultCallback);
  }

Works fine. Do you want me to do a pull request?

Hi, @mikgross . I installed this package today and when I'm trying to use printBitmap I get an error: "width and height must be > 0"

Did you have the same issue? If yes how did you resolve it. Thanks.

orlenko-dmitry commented 2 years ago

Hi @Surile, any updates? I have the same issue.

Surile commented 2 years ago

It has been updated

SVPetrenko commented 2 years ago

It has been updated

@Surile , It has been updated by @mikgross last time. But his fix doesn't work for me. If I try to pass to the printBitmap() method the base64 encoded image and width for it, I'll receive an error: "width and height must be > 0"

orlenko-dmitry commented 2 years ago

I can't pass three params - image, height and width. Typescript returned an error that method accept only two params. With two params the as issue as @SVPetrenko.

Surile commented 2 years ago

@orlenko-dmitry @SVPetrenko Whether to take off data:image/png;base64

SVPetrenko commented 2 years ago

@Surile , sorry, what do you mean?

Surile commented 2 years ago

Whether to delete data:image/png;base64

ngondat97 commented 1 year ago

same issue "width and height must be > 0"

Rehankhalil462 commented 1 year ago

@Surile same issue "width and height must be > 0"

while it SunmiPrinter.printBitmap() accepts only two parameters : encodedString and pixelWidth.

What is the solution?? Help will be much appreciated

Rehankhalil462 commented 1 year ago

@Surile @ngondat97 @orlenko-dmitry @SVPetrenko I found the solution for "widht and height must be > 0" issue.

The image that we are trying to print from the printer has greater width than the receipt of the printer. So, image should be within the 384 width or maybe less than 384. Pass 384 as a pixelwidth of printbitmap method and provide the base64 string of image with the width less than 384 if you are using 58mm paper printer.

I hope this will help .

mikgross commented 1 year ago

I have changed the Bitmap format to base64 string in the main input. and changed the handler as such:

public void printBitmap(String encodedString, Int pixelWidth) throws RemoteException {
    final String pureBase64Encoded = encodedString.substring(encodedString.indexOf(",")  + 1);
    final byte[] decodedBytes = Base64.decode(pureBase64Encoded, Base64.DEFAULT);
    Bitmap decodedBitmap = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
    int w = decodedBitmap.getWidth();
    Integer h = decodedBitmap.getHeight();
    Bitmap scaledImage = Bitmap.createScaledBitmap(decodedBitmap, pixelWidth, (pixelWidth / w) * h, false);
    printerService.printBitmap(scaledImage, innerResultCallback);
  }

Works fine. Do you want me to do a pull request?

Hi, @mikgross . I installed this package today and when I'm trying to use printBitmap I get an error: "width and height must be > 0"

Did you have the same issue? If yes how did you resolve it. Thanks.

Hey man, sory for my late reply. Maybe you already got it working.

I belive your issue is coming from having a wrongly encoded image. Mine is correctly encoded and throws back the width and hight accoridng to what should be.

Didi you resolve your issue?

SVPetrenko commented 1 year ago

Hi, @mikgross. No, it is still not working for me. Currently, I'm using a temporary solution.

Perhaps, you are right. How is it possible to check? Or could you probably tell me which way you encoded an image?

javi2491 commented 1 year ago

Any solution ? I have same error.. @Surile, @mikgross same issue "width and height must be > 0"

Rehankhalil462 commented 1 year ago

Any solution ? I have same error.. @Surile, @mikgross same issue "width and height must be > 0"

Can you share the code of the method that you are using ? And what is your printer paper width specification?

javi2491 commented 1 year ago

Any solution ? I have same error.. @Surile, @mikgross same issue "width and height must be > 0"

Can you share the code of the method that you are using ? And what is your printer paper width specification?

@Rehankhalil462 paper width is 58mm then I have tried like this: RNFS.readFileAssets('profile.bmp', 'base64') .then(content => { console.log('printImage: ' + content); SunmiPrinter.printBitmap(content, 34); }) or Using direct string base64 and removing data:image/bmp;base64 but always i have same result..

Do you have any base64 string that this work ?

Rehankhalil462 commented 1 year ago

@javi2491 try SunmiPrinter.printBitmap(content, 384)

But keep this in mind that the width of the picture that you are trying to print must be less than 384 pixels.

javi2491 commented 1 year ago

@javi2491 try SunmiPrinter.printBitmap(content, 384)

But keep this in mind that the width of the picture that you are trying to print must be less than 384 pixels.

Thanks @Rehankhalil462 , its work for me.

Rehankhalil462 commented 1 year ago

@javi2491 You're welcome. I'm glad to hear this.