Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

2.0 Getting Started

Tres Finocchiaro edited this page Jan 12, 2016 · 21 revisions

###Compatibility

Product Version Supported
QZ Tray 2.0 ✅ Per Roadmap
QZ Tray 1.9 🚫 Per Roadmap
QZ Print 1.9 🚫 Per Roadmap

This is a tutorial for web developers to add a plugin to your web page capable of sending raw commands to your printer. This is common for Barcodes, Thermal Printing, Point-Of-Sales (POS), and other commercial/industry purposes.

This is possible by using JavaScript to talk to the QZ Tray 2.0 software using techniques supported provided by all major web browsers and all major Desktop operating systems.

##Preliminary Steps

This tutorial assumes you have already successfully completed the following tasks:

  1. QZ Tray 2.0 is installed and is working properly in the web browser

  2. Your printer is connected and configured properly.


##The Code

These code examples are also available in sample.html file provided with QZ Tray installation available via QZ Tray, Advanced, Open File Location, demo

Deploy QZ Tray

  1. First, make sure qz-tray.js is included in your web page as well as an ECMAScript 6 Promise library (we include RSVP but support others).

  2. Call qz.websocket.connect() to bind to a local websocket instance of QZ Tray.

    qz.websocket.connect().then(function() {
       alert("QZ Tray connected");
    });

Finding the printer

  1. This code example uses qz.printer.find(..) to find a printer named "zebra" and set it as the currently selected printer.

    qz.printers.find("zebra").then(function(printer) {
       alert("Found " + printer);
    });
    • See also sample.html section findPrinter()

###Raw Printing / Pixel Printing

Depending on what type of printer you have, various functions can be used.

  1. Raw Printing

The Raw Printing Guide goes over how to do the following with a Raw Printer:

  • Sending Raw Commands (Java / php)
  • Base64 Printing
  • Epson/Citizen ESC/P Printing
  • Advanced Print Spooling
  • Print Special Characters
  • File Printing
  • XML Printing
  1. Pixel Printing

The Pixel Printing Guide goes over how to do the following with a standard desktop printer:

  • Print to a File
  • HTML Printing
  • PDF Printing
  • Printing Images

###Serial Communication

  1. If you would like to send and receive commands through a serial connection, please read the Serial Communication tutorial.