qz printing in php

253 views
Skip to first unread message

Sharmily G

unread,
Mar 11, 2021, 12:18:22 AM3/11/21
to qz-print
Hi Guys tried the below code for checking qz runing but i face a issue : Error unable to establish connection with qz tray .

<html>
<head>
<meta charset="UTF-8">
</head> 
<body> 
<!-- USAGE: index.php?var1=some_value_to_print --> 
<?php 
if (isset($_GET["var1"]))
 { echo '<!-- FROM PHP --><script>var var1 = "' . htmlspecialchars($_GET["var1"]) . '";</script>'; } 
else {?> <form action="index.php" method="get">Some value: <input type="text" name="var1"><br> <input type="submit" value="Print"></form></body></html> <?php die(); } ?>
 <!-- FOR QZ TRAY --> <script type="text/javascript" src="https://rawgit.com/qzind/tray/2.0/js/dependencies/rsvp-3.1.0.min.js"></script> <script type="text/javascript" src="https://rawgit.com/qzind/tray/2.0/js/dependencies/sha-256.min.js"></script> <script type="text/javascript" src="https://rawgit.com/qzind/tray/2.0/js/qz-tray.js"></script> 
<script> 
var printer = "Epson"; qz.websocket.connect().then(function() { return qz.printers.find(printer); }).then(function(found) { 
var config = qz.configs.create(found); var data = "\n\n\n\n\n\n\n\n\n\n" + var1 +// echoed above via php "\n\n\n\n\n\n\n\n\n\n"; return qz.print(config, [data]); }).then(qz.websocket.disconnect).then(function() { document.getElementById('status').innerHTML = 'Done'; }).catch(function(err) { document.getElementById('status').innerHTML = err + '<br><a href="qz:launch">Launch QZ</a>'; throw err; }); 
</script> 
<h1 id="status">Attempting to print...</h1>
</body> 
</html>

Please help me in solving the issue

Tres Finocchiaro

unread,
Mar 11, 2021, 1:02:10 AM3/11/21
to Sharmily G, qz-print
Sharmily,

I don't see any errors with your code, it works just fine for me.

I've applied some formatting for easier reading, the code you posted was missing some newlines.

If the connection is not succeeding, there's a good chance that QZ is not running or something went wrong with the installer when it was installing the SSL certificate.

If you're using Firefox, Firefox needs to be restarted after install.

-Tres

var data = "\n\n\n\n\n\n\n\n\n\n" + var1 + /* echoed above via php */ "\n\n\n\n\n\n\n\n\n\n";
return qz.print(config, [data]); })
.then(qz.websocket.disconnect)
.then(function() {
document.getElementById('status').innerHTML = 'Done';
})
.catch(function(err) {
document.getElementById('status').innerHTML = err + '<br><a href="qz:launch">Launch QZ</a>'; throw err;
});
</script>
<h1 id="status">Attempting to print...</h1>
</body>
</html>

--
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qz-print/29637cc2-6569-4e73-89f0-0838e38946dcn%40googlegroups.com.

Tres Finocchiaro

unread,
Mar 11, 2021, 1:08:21 AM3/11/21
to qz-print
You can check if QZ Tray is running using SSL on 8181 by visiting:

https://localhost:8181

If this page shows as untrusted, something went wrong with the certificate install.

Note, the JavaScript files you've linked are for 2.0.  We no longer support this version.  Hopefully you're testing QZ Tray 2.1.2 from our website, which adds better support for certain browsers.

Please share as much information as possible so we can help.
Reply all
Reply to author
Forward
0 new messages