Is there a way to get connected printer name

5 views
Skip to first unread message

Be the Change

unread,
May 20, 2024, 2:02:40 PMMay 20
to qz-print
The way I am planning to use QZ tray in my application is as follows:

1. User won't have an option to find printers and select a printer. Basically this part of UI won't be available in the UI as we are planning on using only one printer (ZDesigner ZD421-300dpi ZPL) for all users which will be hooked directly to their computer.

2. I would like to know of there's any function that I'm missing in the QZ Tray JS where I can get the name of the active printer. Since QZ tray gets the list of cached printers which is present in the Printers and Scanners section of Windows, I am wondering if I could get the name of the printer in some way which is actually connected to the computer.

For example, here's the probem I've noticed. For the first time if I plug in a printer ZDesigner ZD421-300dpi ZPL to someone's machine, I can probably default to this printer always. But I noticed a problem, if I unplug and plug this computer again, I see it getting named to ZDesigner ZD421-300dpi ZPL(Copy 1). 

Hence, in this scenario if I had defaulted my application to the name ZDesigner ZD421-300dpi ZPL, then it won't work and I must have the functionality to have user seect a printer. I am wondering what can I do to bypass this step. Let me know if there's no such thing in QZ tray or it's not a QZ tray related question

Tres Finocchiaro

unread,
May 20, 2024, 2:15:43 PMMay 20
to Be the Change, qz-print
You could try to listen upon events and infer:


It won't tell you which one is active, but might be able to help.  It may also be helpful to notify when the old one goes offline.  https://qz.io/docs/printer-status#listen-for-printer-status

Another workaround is to cache your own listing and assume the latest is the only one that can be used by running qz.printers.find() on a regular basis.

Last, we have qz.printers.getDefault(), which might help if the system auto-switches fo your, but this would vary between OSs.

Tres Finocchiaro

unread,
May 20, 2024, 2:16:20 PMMay 20
to Be the Change, qz-print
To test printer status, you can listen on all events here: 

Be the Change

unread,
May 20, 2024, 5:14:27 PMMay 20
to Tres Finocchiaro, qz-print
Thanks. So basically I can keep on listening to a specific printer events and probably find the most recent one from the timestamp and use that.

Is there anything wrong with not trying to stop listening?

Also, I was looking at the startPrintersListen function of sample.html and noticed that jobData is false, Flavor is always plain. maxJobData is empty string
. what other flavors are available here besides plain?

Also, Once I start listening, then only I can get the status of the specific printer , right?

 /// Status ///
    function startPrintersListen(printerName) {
        var jobData = $("#jobData").prop("checked");
        console.log("What is jobData");
        console.log(jobData);
        var jobDataFlavor = $('input[name="jobDataRadio"]:checked').val();
        console.log("What is jobData Flavor");
        console.log(jobDataFlavor);
       
        var maxJobData = $("#maxJobData").val();
        console.log("What is maxJobData");
        console.log(maxJobData);
       

Tres Finocchiaro

unread,
May 20, 2024, 7:20:16 PMMay 20
to Be the Change, qz-print
Also, I was looking at the startPrintersListen function of sample.html and noticed that jobData is false, Flavor is always plain. maxJobData is empty string
. what other flavors are available here besides plain?

Flavor and maxJobDat are only used by the jobData, which I would recommend is kept off in 99% of environments.  Listening on jobData is for systems that want to -- for example -- print a coupon after a 3rd party job has been received.

With regards to leaving the listeners on, that's just fine. We'll close out any listeners automatically  if the session gets interrupted (tab closed, page navigation, websocket closed).



Reply all
Reply to author
Forward
0 new messages