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

TD2120N and QL810W problems #36

Open
TristanGodal opened this issue Apr 2, 2021 · 3 comments
Open

TD2120N and QL810W problems #36

TristanGodal opened this issue Apr 2, 2021 · 3 comments

Comments

@TristanGodal
Copy link

TristanGodal commented Apr 2, 2021

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
Copy link

robr2112 commented Apr 3, 2021

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

  • The plugin doesn't appear to provide any way to set these UserDefaults (that I can find at a quick glance). So, presumably you must set them yourself some other way. Refer to the BRUserDefaults.h file for a reference to the available keys/values.

  • So, if you have not set the default yourself, the strPaperName will "fallback" to "62mm".

  • And, with QL printers, if the strPaperName does not match the paper that is actually inserted to the printer, then you'll get an error when you try to print. So, I suspect that this is your problem.

  • It seems the plugin defaults generally for a QL model, so most of the other settings are likely OK. But, you may need to experiment with these settings to get your optimal results.

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

  • I don't know how/if this plugin handles paper for TD and RJ series printer models. But, it doesn't seem to support it in the printViaSDK function. So, you will probably have to add the ObjC code yourself.

  • With TD/RJ models, you must call "setCustomPaperFile" on the BRPtouchPrinter object. And, you must pass it path to a paper BIN file.

  • Paper BIN files can be obtained by using the Windows Printer Driver (or the SDK that you can download from Brother website will contain some paper BINs, but these may not be what you need. Usually these are for "Continuous Roll" paper and not labels.)

  • NOTE: Each paper bin file must be "coded" for the specific model you use, so you can't use just any BIN file, it must for the right model.

  • NOTE: Other settings will likely have to change as well, since different settings in BRPtouchPrintInfo will be valid for each different model series.

Hope this helps!

@TristanGodal
Copy link
Author

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
Copy link

robr2112 commented Apr 6, 2021

@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:

  • Copy/Paste/Rename the current "printViaSDK" function. NOTE: Image and PDF printing via the SDK are almost identical.
  • Replace the image parameter to this function with an NSString* parameter that will contain the full path to the PDF file.
  • Replace the "printImage" call with "printPDFAtPath" (with appropriate parameters)
  • Add the new function to the Cordova plugin interface

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

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

2 participants