Last active
January 12, 2023 02:22
-
-
Save tresf/6d219f21c66bfe87cd279a6044b7209a to your computer and use it in GitHub Desktop.
QZ Tray PHP Hello World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment