Default Printer Setup

557 views
Skip to first unread message

Rao

unread,
May 5, 2017, 11:58:32 PM5/5/17
to qz-print

Hello,

First time, I am using QZTray and having trouble in setting up default printer. Created my own SSL certificate and followed the instruction. When I run the sample text file, a message is get displayed as "Printer is not identified" then I selected the printer through the option 'Find Default Printer'. How do I set my localhost printer as default and the same to be used throughout my application. Do I need to make any changes in the code and guide me on setup method.

Note: We are unable to buy the certificate due to cost ($400 per year) as we are very small software company using open source. We are supporting small and medium scale industries where the cost plays a major role. What will be your best offer? If your offer is good definitely I will introduce more companies to buy the certificate.

Regards

Rao

Tres Finocchiaro

unread,
May 6, 2017, 9:13:47 AM5/6/17
to Rao, qz-print
When I run the sample text file, a message is get displayed as "Printer is not identified" then I selected the printer through the option 'Find Default Printer'. How do I set my localhost printer as default and the same to be used throughout my application. Do I need to make any changes in the code and guide me on setup method.

The default printer can be obtained by calling qz.printers.getDefault(), documented here:  https://qz.io/api/qz.printers#.getDefault

To use the default printer name throughout your application you can either chain the getDefault command into each print command or optionally, you may cache this value on pageload to be used later.

Example:

var defaultPrinter;

window.onload = function() {
   qz.websocket.connect()
   .then(qz.printers.getDefault)
   .then(function(printer) {
     defaultPrinter = printer;
   })
   .catch(function(e) { 
      console.error(e);
   });
}

// Called by a button
function printSomething() {
   if (defaultPrinter) {
      var config = qz.configs.create(defaultPrinter, { /* opts */ });
      qz.print(config, [ /* my data to print */ ]);
   } else {
      alert("Could not detect printer.");
   }
}


What will be your best offer?

Our mailing list is public.  Please direct any sales questions privately to sa...@qz.io.  
 

Yeshwanthrao Tharkeswar

unread,
May 8, 2017, 11:12:43 AM5/8/17
to Tres Finocchiaro, qz-print
Hello Tres,

Sorry to bother you again. I followed the below steps to suppress pop-up message using my own self-signed certificate but I failed in my attempt. Both Allowed.Bat and Blocked.bat are blank. What is the mistake I have done?

Regards

Yeshwanthrao
9791696828



This discussion helped a lot, especially knowing that intermediate certificate is not required when you use your own self-signed ones.

So symmarizing everything in one place:

1) generate your private key and certificate by running command like this:

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3650 -nodes

You have either to install openssl for windows or cygwin or just use linux system.
Finally you'll have 2 files:
key.pem - which is private key
and cert.pem - which I guess is public certificate (you can rename it to cert.pem.crt and see its details by windows certificate viewer)

2) Either compile your own build 
https://qz.io/wiki/compiling using your certificate cert.pem.crt
The final build command is 
ant nsis -Dauthcert.use=ant/cert/cert.pem.crt (place your certificate in appropriate folder)

                OR

run your existing installed QzTray using your certificate (using bat file)

javaw -DtrustedRootCert=D:\projects\cert.pem.crt -jar "d:\Install\Progs\Qz\qz-tray.jar"

3) Using qz demo samples - update setCertificatePromise
with something like this
$.ajax("http://domian.dev/qz/certificate.cer").then(resolve, reject);
or $.ajax("http://domian.dev/qz/certificate.cer.txt").then(resolve, reject);

and make sure the web url is accessible as direct link ( http://domian.dev/qz/certificate.cer.txt )

4) Update setSignaturePromise with

$.ajax(" http://domian.dev/qz/sign-message.php?request=" + toSign).then(resolve, reject);

In sign-message.php
use your private.key you've generated at step 1

$KEY = 'key.pem'; // for your security place the private key in non-accessible directory from web
$PASS = '';
$req = $_GET['request'];
$privateKey = openssl_get_privatekey(file_get_contents($KEY), $PASS);
//.........

Reply all
Reply to author
Forward
0 new messages