AbobosSoftware / cordova-plugin-brother-label-printer

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

TD2120N and QL810W problems #36

Open TristanGodal opened 3 years ago

TristanGodal commented 3 years ago

Hello, I'm starting using this cordova plugin. I got some problems when trying to detect devices. I'm working with Ionic 5+ and I'm just using this code :

Top of file :

declare var cordova: any;

In my ngOnInit():

    cordova.plugins.brotherPrinter.findNetworkPrinters((data) => {
      alert(JSON.stringify(data));
    }, (error) => {
      alert(error);
    });

My 2 label printers are on same network but the code above is returning an empty array.

Does anyone has an idea ?

Thanks.

EDIT :

I just achieved to detect my QL810W by modifying Info.plist on iOS.

Now when I try to print after setting the the printer, the console returns me :

ERROR: Printing failed on ip:192.168.22.219, model:QL_810W, port: NET with message : "ERROR_INVALID_PARAMETER_"

Code :

cordova.plugins.brotherPrinter.findNetworkPrinters((data)=>{
        var printerResponse = data[0];
        var printer = {
          "model": printerResponse.model,
          "port": printerResponse.port,
          "modelName": printerResponse.modelName,
          "ipAddress": printerResponse.ipAddress,
          "macAddress": printerResponse.macAddress,
          "nodeName": printerResponse.nodeName,
          "location": ""
        }

        alert(JSON.stringify(printer));

        cordova.plugins.brotherPrinter.setPrinter(printer, function (success) {
          let base64Image = "data:text/plain;base64,TWFuIGlzIGRpc3Rpbmd1aXNoZWQ=";
          var imageString = base64Image.split(',')[1];

          cordova.plugins.brotherPrinter.printViaSDK(imageString, (data) => {
            alert('print success');
          }, (error)=> {
            alert('error:' + error);
          })
        });
      },(err)=>{
        alert("Error" + err);
   });

Any idea ? Thanks.

robr2112 commented 3 years ago

The problem is likely that you have not set the "Printer Settings" correctly to be appropriate for the printer model and paper that you are using.

If you look at the ObjC code for "printViaSDK" in BrotherPrinter.m, you'll see that it loads BRPtouchPrintInfo object settings from UserDefaults. For example: printInfo.strPaperName = [self stringValueFromDefaults:userDefaults forKey:kPaperLabelName withFallback:@"62mm"]; // Item 2

When you get to the TD2, this will have a completely different way of handling the paper.

Hope this helps!

TristanGodal commented 3 years ago

Thank you, it works. Actually I just work with PDF to print. This plugin is expecting BMP file, is there a way to print the PDF ? Cause converting a PDF to BMP in javascript is quite tricky.

Thanks.

robr2112 commented 3 years ago

@TristanGodal Great! Glad that helped.

The iOS SDK actually has an API named "printPDFAtPath" (in v3 APIs, which is what this plugin is currently using). This API is used to print PDF files. I'm not certain if the Android SDK has similar capability if you need to support Android too; I believe the Android SDK requires printing each page of a PDF as an image, like this plugin allows. I support the iOS SDK, so I'm not 100% sure about Android.

As Brother does not "officially" support this plugin (I support it out of courtesy), I will not modify it myself to support PDF. But, you are welcome to try yourself. You can issue a Pull Request if you are successful to add both iOS and Android.

Of course, plugins will require both iOS and Android side....for Pull Request you can't do just one side. And, these modifications will require using the "native" programming languages for each platform, plus understanding the details about Cordova plugins (which I am not an expert with).

On iOS side, it would be pretty easy to do:

On Android side, refer to the SDK sample app (included with SDK download from our website) to see how it handles PDF files. Then, repeat what I mentioned above for iOS on the Android specific Java code inside this plugin. Then, modify the implementation in Java per how the SDK Sample app handles each PDF page.

Good luck!

Cheers, Rob