AbobosSoftware / cordova-plugin-brother-label-printer

Cordova and Capacitor plugin for Bother Label Printers
MIT License
10 stars 16 forks source link

printViaSDK input format, ERROR_WRONG_LABEL #22

Closed musla closed 1 year ago

musla commented 4 years ago

Hello, using this plugin with ionic v3 on Android and bluetooth connected QL-820NWB. Installed is default label paper (I guess it is W62 endless).

Could you please give more detailed information about data format to be sent to printViaSDK? I always get the ERROR_WRONG_LABEL, so obviously I am sending incorrect data to the printer.

Is there any command how to set the paper format? (perhaps via sendUSBConfig)?

I am trying to send base64encoded image (generated on https://www.base64-image.de/). Should the data be sent with 'data:image/png;base64,' prefix on without? Are there any size or proportions requirements? Could you please give some working base64encoded image example?

Thank you!

brotherMobileDev commented 4 years ago

Hey Musla.

Jack here from Brother Mobile Solutions.

So we think the problem is how you're setting the label. Try the following: mPrinterInfo.labelNameIndex = LabelInfo.QL700.W62.ordinal(); Don't forget: mPrinter.setPrinterInfo(mPrinterInfo) I am aware this says QL700 and you are using an 820NWB, but this is correct. Using QL700 for all 700 and 800 series QL printers is correct for this field.

For the QL printers, the cartridge has a set pin-mapping that tells the printer what size of cartridge has been inserted. So setting the paper format is not necessary.

As for the base64encoded image. base64 isn't a format the SDK handles. In order to print an image of this encoding, you'll need to convert it to a Java bit map. If you were converting this image from a PNG, JPEG, or JPG, you could just send that file straight through using printer.PrintFile(filePath); If you are sending a bitmap, you would send it using printer.PrintImage(bitmap);

I am happy to answer any further questions you may still have.

Feel free to use our online Reference Guide: https://support.brother.com/g/s/es/htmldoc/mobilesdk/reference/android/printer.html

arcadius commented 4 years ago

@musla , please what is the name of the label in the printer? Could you share the ionic code you are using?

musla commented 4 years ago

Hello Jack at @brotherMobileDev , thank you for reply. You reffer to the java methods of brother's SDK. Please note that we are using this cordova plugin and it's javascript interface has limited functions. It would mean to fork and change the plugin itself what we would like to avoid.

As on base64encoded bitmap I am referring to the printViaSDK method of this plugin, which is using printImage od brtoher's SDK.

Thank you! Tomas

musla commented 4 years ago

Hello @arcadius , the label is DK 62mm x 5m, WhitePaper.

The code:

findPrinter() {
      this.sdk.findBluetoothPrinters((success) => {
          console.log("printers discovery:", success);
          if (success.length > 0) {
              var printer = {
                  "model": success[0].model,
                  "port": success[0].port,
                  "modelName": success[0].modelName,
                  "ipAddress": success[0].ipAddress,
                  "macAddress": success[0].macAddress,
                  "nodeName": success[0].nodeName,
                  "location": "",
                  "paperLabelName" : "W62H29" /*does not work also without this line*/
              };
              this.selectedPrinter = printer;
              this.sdk.setPrinter(this.selectedPrinter, function (success) {
                  console.log('printer set', success);
              });
          }
      }, (failure) => {
          console.log('finding printers failed', failure);
      });
  }
  print(base64String) {
      return new Promise((resolve, reject) => {
          console.log('printing', base64String);
          this.sdk.printViaSDK(base64String, function (printResult) {
              console.log('print done', printResult);
              if (printResult == null) {
                  // iOS result
                  console.log('iOS?');
                  resolve(1);
              }
              else {
                  if (printResult.result != null && printResult.result !== undefined) {
                      if (printResult.result == 'Succeeded') {
                          // Print Success
                          console.log('looks like printed');
                          resolve(1);
                      }
                      else {
                          console.log('looks like printer error');
                          resolve(2);
                      }
                  }
                  else {
                      console.log('looks like printer error2');
                      resolve(2);
                  }
              }
          });
      });
  }  

The example string base64string: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAbhSURBVHjaYiw5qsMwCogDAAHENBoExAOAABoNLBIAQACNBhYJACCARgOLBAAQQKOBRQIACKDRwCIBAATQaGCRAAACaDSwSAAAATQaWCQAgAAaDSwSAEAAjQYWCQAggFgG3AXK/KZSXBqcLLxABi41dz+e/v7n87NvN559vQFkDJRTAQJoYAJLiltDR8gJGDpKfCbEqEdW9uzrzbufTl99tw8YgnR2NkAAMdJz1AGYfExEA2ylYgTZpSg37cffL6dfbTj8bPH7n8/o436AAKJTYAFDx002S0fYmYOZh+qGn3m1cdfjaXQIMoAAonlgAVOT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AOBgAQQOQEFnnz74N2HSXxACCAyMuGN8jKhupDfTwaIIDISlmfyFzZ4Ua9hcMDAgACiJzAAu3AJauMB+bEIZ24AAKIzO4O2YkrgrJ1zQMLAAKIzMA682ojeRqBDa6hmxkBAojMwAKW8eTlRAbabEGiDwAIIPJHHQ4/X0y2XkqWzg8gAAgg8gPr6rt9ZK9Kh4SXn2I5FXch0QEABBCzVbIYeTr//PvFysROyTSiPK+egYjns283aTp6A+xmOcoke8kXGop6kl3UQgBAAFE0RAPMiRRuqwe2JDK05937dOb0qw0U+gQtgIC9K2BEAhHceUBbKDQWIIAoCixgg2vj/Q5ghqLQEcAqEoj8FSuuvN0LbJQAu1OkpjXIGldgGElza9BuhAMggCgd/AMmB1OxAKq4D5gEgKU+pOAHlobACvfdj6d4Qg1SAgADiNYnRsABQABRYaR0xe3qIoO11HUx0DRIchtUBTxAAFFhwgIY+cDMyDACAEAAUWd2B5gZDz9fMuwDCyCAqDYVtul+JxWrs8EJAAKImvOGK+/UDO/wAgggKk+yDu/wAggg6s9IA8Nr0/2uYRlYAAFEk+l7YMu+/2Lo4JmCphYACCBarXUA72d23/14+nAKLIAAou3CkF2PpwGDbJCUYpTvHAIIIPqd+QfscgM7RnTrmsAB/ISNKxTvSQMIIEY632GhI+RE+QkgxAQQsBwAdsiBAUTFxRkAAcQ4UBd+gMZPwKMoVOkJw0Pn3c+nz77epNHqFYAAGrATcIEeA81sPwaxwRsYNSDn4AIzLMHtIvDRCMgkE91OdwUIoIE/LhhS9ELDbnADgAAaXSZJAgAIoNHAIgEABNBoYJEAAAJoNLBIAAABNBpYJACAABoNLBIAQACNBhYJACCARgOLBAAQQKOBRQIACKDRwCIBAATQaGCRAAACaDSwSAAAAQYAIa4T8UEhfhUAAAAASUVORK5CYII= Tried with and without "data:image/png;base64," prefix.

What I need to achieve is to print visitor badges - name, surname, company, date, event name for a conference. I was also looking to define brother label template (.lbx), send to printer and later sending just text to the app. But that seems to be overcomplicated, so generating bitmap from the input text looks like easier approach, but still not very optimal (text => bitmap => print).

Thank you, Tomas

brotherMobileDev commented 4 years ago

@musla

Thanks for the response.

After talking to another developer here, he further explained this to me as well. We looked into the Cordova code and saw that there are "hooks" for these methods to be utilized in the plugin code. So maybe in a future update, they'll be implemented! Or not. It's up to @arcadius.

robr2112 commented 4 years ago

@musla

the label is DK 62mm x 5m, WhitePaper.

It seems you have a CONTINUOUS label.

"paperLabelName" : "W62H29" /does not work also without this line/

This seems to be the wrong paper name for the label you have. You should try using"W62" instead (as far as I understand this printer model, which is not one we usually support).

From what I can follow in the code, it seems the "W62H29" will be saved to preferences and recalled from preferences at print time. So, once you save this string to prefs once, it'll be there until you replace it with something else. Thus, the default value of W62, which SHOULD work, will not be used, even if you don't specify this line. Am I right about this @arcadius?

Anyway, please try using W62 and let us know if this works.

-Rob

arcadius commented 4 years ago

@robr2112 is correct .... label would be 'W62' or 'W62RB' if you have red/black one

See all possible values at

interface Printer {
    model: string // Usually of the form 'QL_720NW' on Android
    port: 'NET' | 'BLUETOOTH'
    modelName: string // Usually of the form 'Brother QL-720NW'
    ipAddress?: string
    macAddress?: string
    serialNumber?: string
    nodeName?: string
    location?: string
    paperLabelName?: string // 'W17H54'|'W17H87'|'W23H23'|'W29H42'|'W29H90'|'W38H90'|'W39H48'|'W52H29'|'W62H29'|'W62H100'|'W12'|'W29'|'W38'|'W50'|'W54'|'W62'|'W60H86'|'W54H29'|'W62RB' 
}

https://github.com/MenelicSoftware/cordova-plugin-brother-label-printer#interface-reference

Please note that findPrinter() is not necessary if you have a static IP for the printer.

arcadius commented 4 years ago

I have also added sample code at https://github.com/MenelicSoftware/cordova-plugin-brother-label-printer/blob/master/README.md#sample-code

musla commented 4 years ago

Thanks for help @robr2112 and @arcadius !

The issue was really in the paperLabelName. Using "W62RB" works fine. It does not work with "W62". I am wondering why the paper label must be defined when the printer itself knows what is inserted...

As a side question: my goal is to print visitor badges. Is there any better way than generating an image and sending to printer as image?

Thank you! Tomas

arcadius commented 4 years ago

@musla , are you developing an app for printing visitor badges? We have this one https://smartlobby.co/ We could offer you some discount if needed :-)

musla commented 4 years ago

@arcadius have seen it :) Yes, we are extending our event management system (https://eventplace.cz/en) with an app for on-site checkin. (get visitors db, scan QR, print badge). Would welcome your approach for badge creation. Let's continue in PM.

robr2112 commented 4 years ago

@musla Great that you were able to resolve by changing paper to W62RB!

I am wondering why the paper label must be defined when the printer itself knows what is inserted...

Good question. I'm not sure. But, probably the SDK needs to know, and maybe it can't read it from the printer, at least with all I/O channels. Just a guess (as I didn't create the SDK). The RJ-series models we support also have strange issues with SDK and specifying paper.

Is there any better way than generating an image and sending to printer as image?

I see you're already in discussions with @arcadius. And, you've already mentioned the possibility of using Templates, which is what I would suggest as an alternative. But, if the speed of printing the label by sending an image is sufficient for your needs, then I personally don't think it's worth the effort to switch to the template system.

Template mode adds other complications (template design, and template management on the device and printer. especially if multiple templates are needed).

A 3rd possibility would be to design the labels using the ZPL printer language (and then send using this plugin as a configuration file, assuming that supports your WIFI interface). It seems QL-820NWB does support ZPL. This eliminates template management. You may have to learn the ZPL language, but it's not that difficult to do for a basic label. Though, if you have images in the label, you need to generate the correct data format for that. There's always trade offs. It all depends on your specific needs.

-Rob

arcadius commented 1 year ago

Closing as @musla got it working

robr2112 commented 1 year ago

About @musla's comment saying: I am wondering why the paper label must be defined when the printer itself knows what is inserted...

See my response here: https://github.com/MenelicSoftware/cordova-plugin-brother-label-printer/issues/19#issuecomment-1198734479

-Rob