-
Notifications
You must be signed in to change notification settings - Fork 55
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
Comments
Can you send the output of objPrintersAll array after printerSearchSuccess() is called? |
This is the output as JSON string: There is only one printer found, which is correct. |
Hi, Thank you in advance, |
@dandray did you ensure the image is encoded properly, and isn't a raw bitmap? From the docs:
|
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;
}
} |
Hi @gordol, 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 : |
Hi @gordol , Error: "Unexpected Internal System Error: IllegalArgumentException" using printer brother QL-1110NWB this is my code |
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.
The text was updated successfully, but these errors were encountered: