Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing failed #43

Open
thebbel opened this issue Dec 18, 2018 · 7 comments
Open

Printing failed #43

thebbel opened this issue Dec 18, 2018 · 7 comments

Comments

@thebbel
Copy link

thebbel commented Dec 18, 2018

We use the brother-sdk-upgrade branch. We try to print on the Brother QL820NWB. The printer is found by the plugin and can be selected. The printViaSDK function also calls the success callback. But nothing is printed. The status message displayed is ERROR_BROTHER_PRINTER_NOT_FOUND.

Here is our code:

var objPrintersAll = [];

document.addEventListener('deviceready', function(event) {
printerSearch();
});

function printerSearch(){
cordova.plugins.brotherPrinter.findBluetoothPrinters(printerSearchSuccess, printerSearchError);
}

function printerSearchSuccess(printers){
objPrintersAll = printers
printerSet();
}

function printerSearchError(reason){
alert('error: ' + reason);
}

function printerSet(){
cordova.plugins.brotherPrinter.setPrinter(objPrintersAll[0], printerSetSuccess, printerSetError);
}

function printerSetSuccess(){
var img = "base64string";
cordova.plugins.brotherPrinter.printViaSDK(img, printerPrintSuccess);
}

function printerSetError(reason){
alert('error: ' + reason);
}

function printerPrintSuccess(status){
alert('Printed ' + status);
}

Did we miss something? Any help is welcome. Thank you very much.

@gordol
Copy link
Owner

gordol commented Dec 27, 2018

Can you send the output of objPrintersAll array after printerSearchSuccess() is called?

@thebbel
Copy link
Author

thebbel commented Dec 27, 2018

This is the output as JSON string:
[{"model":"QL_820NWB","port":"BLUETOOTH","modelName":"QL-820NWB1259","macAddress":"CC:78:AB:8C:F6:7F"}]

There is only one printer found, which is correct.

@dandray
Copy link

dandray commented Jan 17, 2019

Hi,
I also try to print to the same model than you, from an ionic app.
I tried with the normal plugin "printer" and the brother printer gives me an error : "Wrong roll type".
Afterwards I tried with this plugin, by just calling cordova.plugins.brotherPrinter.printViaSDK() function, passing a bitmap image (via document.getElementById('image') which is a bmp image in my html, but it says to me that a bitmap file is expected.
Could someone explain how could use it properly in Ionic ?

Thank you in advance,
Dan

@gordol
Copy link
Owner

gordol commented Jan 17, 2019

@dandray did you ensure the image is encoded properly, and isn't a raw bitmap?

From the docs:

printViaSDK takes one parameter, which is a base64 encoded bitmap image.

@gordol
Copy link
Owner

gordol commented Jan 17, 2019

You don't say what branch you're using, but from the dev branch, the following code is used for printViaSDK image decoding. As you can see, it requires a base64 encoded bitmap.

        Bitmap bitmap = null;
        try {
            String encodedImg = args.getString(0);
            bitmap = bmpFromBase64(encodedImg);
        } catch (JSONException e) {
            e.printStackTrace();
            PluginResult result = new PluginResult(PluginResult.Status.ERROR, "An error occurred while trying to retrieve the image passed in.");
            callbackctx.sendPluginResult(result);
            return;
        }

        if (bitmap == null) {
            PluginResult result = new PluginResult(PluginResult.Status.ERROR, "The passed in data did not seem to be a decodable image. Please ensure it is a base64 encoded string of a supported Android format");
            callbackctx.sendPluginResult(result);
            return;
        }

bmpFromBase64 looks like this:

    public static Bitmap bmpFromBase64(String base64){
        try{
            byte[] bytes = Base64.decode(base64, Base64.DEFAULT);
            InputStream stream = new ByteArrayInputStream(bytes);

            return BitmapFactory.decodeStream(stream);
        }catch(Exception e){
            e.printStackTrace();
            return null;
        }
    }

@dandray
Copy link

dandray commented Jan 20, 2019

Hi @gordol,
Thank you for your answer. Actually I just converted online a png image into a bmp to do my test. I don't know how I can see this information, but like you said I guess that it is not a base 64 encoded bitmap image.
Concerning the branch that I use, I am not sure because I installed it through "cordova plugin add cordova-brother-label-printer", and I don't see in the README or in the LICENSE file wether it is dev branch or master.

Coming back to my error, what I really want to do is anyway a bit different : I would like to print a div section of my code, so I presume that I have to convert it into a base64 bitmap and afterwards print it via the brotherPrinter.printViaSDK() function.

I put here the code of the function that I call from a button in order to print, to know if I am wrong in the way I try to do it for the moment :
printQR() : void{ (<any>window).brotherPrinter.printViaSDK(BASE64ENCODEDBMP, function(err){ console.log("Error while printing"); }); }
Do I miss something or is it enough to do what I need ?

@firdaus48
Copy link

firdaus48 commented Jan 28, 2020

Hi @gordol ,
I am getting following error after calling printViaSDK.

Error: "Unexpected Internal System Error: IllegalArgumentException"

using printer brother QL-1110NWB

this is my code
let image = "isbase64Image"; //sample actually use base64
cordova.plugins.brotherPrinter.printViaSDK(image, function (printResult) {
//var printResult = callback;
console.log(printResult);
},function (err){
console.log(err);
});
Thank you. please help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants