Can I use QZ API to print automatically to my local printer from my website?

2,187 views
Skip to first unread message

olimits7

unread,
Dec 20, 2016, 1:25:32 PM12/20/16
to qz-print
Hi,

I need to print 2 PDF documents, one document off a "Zebra" printer and the other document on a regular "Samsung" laser printer.

With the QZ API, can I automatically print these documents from my website if I setup a "Print Documents" button integrated with the QZ API?

Also, would I be able to configure how many copies I need of each document?

Thank you!

Tres Finocchiaro

unread,
Dec 20, 2016, 4:46:31 PM12/20/16
to olimits7, qz-print

With the QZ API, can I automatically print these documents from my website if I setup a "Print Documents" button integrated with the QZ API?



Also, would I be able to configure how many copies I need of each document?

--
You received this message because you are subscribed to the Google Groups "qz-print" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bernie

unread,
Dec 20, 2016, 5:53:20 PM12/20/16
to qz-print, olim...@gmail.com

Hi Tres,

Thank you for the quick reply!

Ok, great; I'm glad that QZ can do those things.

I've been looking over the following "signing messages" Wiki document, I currently have an SSL installed on my website would I be able to just use the SSL keys I have with QZ?

https://qz.io/wiki/2.0-signing-messages

Thank you!
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+u...@googlegroups.com.

Tres Finocchiaro

unread,
Dec 20, 2016, 6:32:15 PM12/20/16
to Bernie, qz-print
> I currently have an SSL installed on my website would I be able to just use the SSL keys I have with QZ?

Not specifically, no.  If you wish to use QZ Tray with your own certificate for signing, you can use any self-generated PKCS#1 key and matching certificate and the custom cert will need to be provided at startup -- either through a custom startup command line argument, or via qz-tray.properties.


Bernie

unread,
Dec 21, 2016, 12:33:08 AM12/21/16
to qz-print, olim...@gmail.com
Hi Tres,

Thanks for the reply!

I use Plesk to host my website on a dedicated server, and through Plesk I can create a self-signed certificate that I can download the *.pem file which contains the "private key" and "certificate"; would I be able to use this with QZ Tray?

I'm trying to get a better understanding on how this will all work; I would first install the QZ Tray client on the PC which has the printers that I need to print to from my website, right?

My website is built in PHP; how would my developer be able to send an API call this way my PDF documents get printed on the PC I have QZ Tray installed on?  Usually, with other APIs we've worked with there is an submit URL where we would submit requests to but I'm not sure if this is how QZ Tray works as well?

Thank you, again!

Tres Finocchiaro

unread,
Dec 21, 2016, 12:45:12 AM12/21/16
to Bernie, qz-print
Bernie,

QZ Tray is 100% JavaScript API driven and it uses technology known as JavaScript Promises to allow synchronous yet non-blocking print control from a web page.

From a PHP perspective, this generally means the PHP developer will provide the content (usually in the form of an AJAX request from JavaScript) and then the data will be provided to our library using JavaScript.  This mix of languages is common with our API.

If you prefer a pure-PHP solution, are some other libraries which specialize in server-driven printing.

In regards to suppressing the warnings/signing messages, the cert and private key from Plesk may very well work.

If you're just trying to suppress the dialogs for evaluation purposes, please feel free to contact sa...@qz.io and request a 30 day demo certificate.

--
You received this message because you are subscribed to the Google Groups "qz-print" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+unsubscribe@googlegroups.com.

Bernie

unread,
Dec 21, 2016, 1:20:05 AM12/21/16
to qz-print, olim...@gmail.com
Hi Tres,

Ok, that's fine; I'm sure my developer won't have any issues using the JS API.

I installed QZ Tray on my PC and I was able to test out the printing using the "sample.html" page; which seemed to work properly. 

However, I'm still confused in how I would be able to send print jobs "silently" from my website to my local PC that has QZ Tray installed using the JS API?

https://qz.io/wiki/2.0-getting-started

I was taking a look at the above "bare-bone example" and I see the section talking about "qz.websocket.connect()", but how would I actually use this from my website to connect to my local PC QZ Tray to send print jobs?

If you're just trying to suppress the dialogs for evaluation purposes, please feel free to contact sa...@qz.io and request a 30 day demo certificate.

Ok, great...once we are ready to test this integration I'll reach out to sa...@qz.io for a demo certificate and if it works then I can always try to test this with a Plesk self-signed certificate.

Thank you,

Bernie
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+u...@googlegroups.com.

Tres Finocchiaro

unread,
Dec 21, 2016, 1:31:11 AM12/21/16
to Bernie, qz-print
However, I'm still confused in how I would be able to send print jobs "silently" from my website to my local PC that has QZ Tray installed using the JS API?

Assuming you want it to be purely silent (not even the press of a button on you page), you'd trigger the connect and print events on page load.

If you're on a landing page and need to receive the print events without navigating away, you'd need some sort of timer to fetch the data periodically.

i.e. If you can display an alert dialog, you can send the print job to the printer.

The chaining requests example from the first reply above is more comprehensive.  Here is is again:  https://qz.io/wiki/2.0-Pixel-Printing#chaining-requests

-Tres

Bernie

unread,
Dec 21, 2016, 1:51:13 AM12/21/16
to qz-print, olim...@gmail.com
Hi Tres,

Oh ok, I think I'm misinterpreting what "silent" means; I thought it was the PDF wouldn't open and send the print job directly to the printer.  However, the way I was planning on setting this up was to actually have "Print Documents" button that would send the print job directly to the printer without opening up the PDF; so I guess this is not considered "silent".

Ok, but regarding the "qz.websocket.connect()" how exactly would this work to connect to my local PC? 

I'm not sure if this will be an issue but the local PC I need to print to sits behind a wireless "Verizon JetPack" connection and also sometimes connects to "Xfinity" free Wi-Fi too.  So currently for my "Verizon JetPack" connection, I just have an internal IP address like 192.168.1.5 and I'm not sure if I can do any port forwarding with "Verizon JetPack"...would this cause an issue with using QZ Tray?

Thank you,

Bernie

Tres Finocchiaro

unread,
Dec 21, 2016, 1:55:24 AM12/21/16
to Bernie, qz-print
The qz.websocket.connect() talks back to your PC on localhost.

QZ Tray fires up a miniature web server on your computer (Jetty) and qz.websocket.connect allows the browser to talk back to your local computer and get information such as attached printers, etc.

The PDF can be supplied by URL and Java will attempt to download it, or you can provide the PDF as a large text base64 string using JavaScript.
--
You received this message because you are subscribed to the Google Groups "qz-print" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+unsubscribe@googlegroups.com.

Bernie

unread,
Dec 21, 2016, 2:07:04 AM12/21/16
to qz-print, olim...@gmail.com

Oh ok, I see...under my local PC QZ Tray in the "About" screen I see "wss://localhost:8181"; so my developer would need to connect, for example to "wss://{local_pc_ip_address}:8181" then once connected we could then use JS API to send print jobs?

If this is correct, then each time my IP address changes I have to keep updating my website so it points to the new "local PC IP address" this way it can connect back to QZ Tray?

Thank you,

Bernie
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+u...@googlegroups.com.

Tres Finocchiaro

unread,
Dec 21, 2016, 2:09:47 AM12/21/16
to Bernie, qz-print
Unless you're running QZ Tray on a local server, you don't need to change any code.  The browser looks at "localhost" which will always be the same PC as the browser. Note, QZ Tray will need to be installed on each PC that need to print.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+unsubscribe@googlegroups.com.

Bernie

unread,
Dec 21, 2016, 1:20:41 PM12/21/16
to qz-print, olim...@gmail.com
Ok, my website is hosted on a dedicated server at OVH; so that's good that I don't need to change any code.  And currently I just need to install "QZ Tray" to one local PC that has the printers I need to print to.

1. Is the online https://demo.qz.io/ demo version currently working?  I get a "Error: The current connection attempt has not returned yet" and "TypeError: _qz.websocket.connection is null" errors when I try to use it.

2. Regarding the "Signing Messages" part, is this something that I have to do in my local PC copy of QZ Tray or on my website?

3. Also, if I'm going to try to use my Plesk self-signed certificate for "signing messages"; should I have my developer follow the steps in this https://qz.io/wiki/2.0-signing-messages link or the other http://www.google.com/url?q=http%3A%2F%2Fstackoverflow.com%2Fa%2F40275815%2F3196753&sa=D&sntz=1&usg=AFQjCNESfE-nwAPPdbtUSR_yRyneVGbZtQ link you sent me?

Thank you!

Tres Finocchiaro

unread,
Dec 21, 2016, 1:28:35 PM12/21/16
to Bernie, qz-print
>  "Error: The current connection attempt has not returned yet" and "TypeError: _qz.websocket.connection is null" errors when I try to use it.
 
That shouldn't happen.  Is QZ Tray running?  If not, you can click the "Launch QZ" button.

 Inline image 1

> [...] self-signed certificate for "signing messages"; should I have my developer follow the steps in [sign-messages] or [stack overflow] link you sent me? 

Stack overflow makes specific reference to "signing messages", so that's really the way to go if you plan to use the free version.

Bernie

unread,
Dec 21, 2016, 1:40:50 PM12/21/16
to qz-print, olim...@gmail.com
Yes, I have "QZ Tray" currently running.  I tried clicking the "Launch QZ" and it returns with that "Error: The current connection attempt has not returned yet" error.

Ok, by using the Stackoverflow method, will this still be secure so only my website will be verified by QZ tray?

Thank you.

Tres Finocchiaro

unread,
Dec 21, 2016, 1:57:51 PM12/21/16
to Bernie, qz-print
Ok, by using the Stackoverflow method, will this still be secure so only my website will be verified by QZ tray?

Yes.  If you create the certificate and never share the private key, it will be secure.

--
You received this message because you are subscribed to the Google Groups "qz-print" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+unsubscribe@googlegroups.com.

Bernie

unread,
Dec 21, 2016, 2:14:10 PM12/21/16
to qz-print, olim...@gmail.com
Ok, thank you!

Is there anything else I can try to get the online demo to work this way I can see how this actually works with a "live" site?

Thank you.
To unsubscribe from this group and stop receiving emails from it, send an email to qz-print+u...@googlegroups.com.

Tres Finocchiaro

unread,
Dec 21, 2016, 2:15:50 PM12/21/16
to Bernie, qz-print
Is there anything else I can try to get the online demo to work this way I can see how this actually works with a "live" site?

No, all "live" steps have been provided. 

Bernie

unread,
Dec 21, 2016, 2:23:20 PM12/21/16
to qz-print, olim...@gmail.com
Ok, it seems to be a Firefox issue, I'm currently running v.50.1.0, because when I tried with Chrome and IE 11 it works and I would get the following pop-up but with Firefox I don't.  I even tried to run Firefox in a private window but I still did not receive the popup.

https://gyazo.com/752f86da335d7857515e8a4c38e4c900

Tres Finocchiaro

unread,
Dec 21, 2016, 2:27:19 PM12/21/16
to Bernie, qz-print
Due to some decisions by Mozilla, Firefox requires an explicit restart after QZ Tray has been installed if you are testing against an HTTPS website.  This is true for Mac, Linux and Windows.

This is mentioned in our browser compatibility chart.

Bernie

unread,
Dec 21, 2016, 2:52:14 PM12/21/16
to qz-print, olim...@gmail.com
Ok, yes that worked...thank you!
Reply all
Reply to author
Forward
0 new messages