Wiki - 1.9 Raw Printing

Compatibility

Contents

The following code can be used for raw printing only. If you are unsure what raw printing is, please refer to What is Raw Printing?

Raw Commands

  1. JavaScript

    1. Insert (or modify) this JavaScript code to send commands to the printer. This button has already been provided in sample.html
    function print() {
      qz.append("A37,503,0,1,2,3,N,QZ-PRINT TEST PRINT\n");
      qz.print();
    }

    See also sample.html section print().

    Note: The raw commands provided in the sample may not work with your printer. Please reference your printer's programming guide for more information.

    1. Add HTML code for a Print button. This button has already been provided in sample.html.
    <input type="button" onclick="print()" value="Print"></input>
    1. Test print.html
      • Load page in web browser and click "Find Printer" button.
      • Click "Print" button.
  2. php

    1. If you would rather use php, replace print() function with this code:
    Using echo
    <?php ?>
    <script>
      function print() {
         qz.append(<?php echo $commands; ?>);
         qz.print();
      }
    </script>
    Using a dedicated php file
    <?php ?>
    <script>
      function print() {
         qz.appendFile("http://mydomain/myfile.php");
      }
    
      function qzDoneAppending() {
         qz.print();
      }
    </script>

ZPL printing

ZPL sample commands

Base64 printing

With this function, you can send base64 encoded characters/raw commands to qz using "append64". This will automatically convert provided base64 encoded text into text/ascii/bytes, etc.

   function print() {
      qz.append64("SEVMTE8hICBZT1UgQVJFIFJFQURJTkcgQSBERUNPREVE");
      qz.append64("IEJBU0U2NCBNRVNTQUdFIFNFTlQgRlJPTSBKWkVCUkEu");
      qz.print();
   }

ESC/P Printing

Epson, Citizen, Star, Bixolon

  1. Optional CHR() function for easier reading.

    function chr(i) {
      return String.fromCharCode(i);
    }
  2. Open cash drawer (usually connected to printer via cable).

    function openCashDrawer() {
      qz.append(chr(27) + "\x70" + "\x30" + chr(25) + chr(25) + "\r");
      qz.print();
    }
  3. Cut paper.

    function cutPaper() {
      qz.append(chr(27) + chr(105));       // cut paper
    }
  4. Basic font styling.

    function boldAndCenter() {
      qz.append(chr(27) + chr(69) + "\r");  // bold on
      qz.append(chr(27) + "\x61" + "\x31"); // center justify
    }

Advanced Print Spooling

The ability to control spooling to the printer in batches (e.g. 5, 10, etc). This has advantages due to buffer limitation on certain printer models where submitting 100+ labels randomly stop in the middle of printing. In addition, some programmers have had success with using it for easier reprints.


Special Characters

If special ASCII, CHR, hex or escape characters need to be printed, use the char code, or the \x notation. Note, the NULcharacter (i.e. \x00) is not supported in JavaScript, so appendHex(...) is needed.

   function print() {
     // Appends CHR(27) + CHR(29) using `"fromCharCode"` function
     qz.append(String.fromCharCode(27) + String.fromCharCode(29));

     // Appends hexadecimal data
     qz.appendHex("x00x01x02xFF");

     // Send characters/raw commands to printer
     qz.print();
   }

   // Force special DOS/Win characters on UNIX/Linux
   qz.setEncoding("cp866");       // or
   qz.setEncoding("cp1252");

   // Force UTF8 characters on Windows

   qz.setEncoding("UTF-8");

   // Force MS/DOS Western Europe  (i.e. "Maçã")
   qz.setEncoding("850");

   // Submitted via Simon on mailing list jzebra-users@googlegroups.com
   // Print GBP '£' sign using ESC/P
   // First change code page to UK
   qz.appendHex("x1Bx52x03");
   // Then just use '#' where you want your E
   qz.append("#5.00");

File Printing

This feature allows a raw file to be spooled directly to the printer.


XML Printing

The ability to read the contents of an XML file containing Base64 encoded commands and send these commands to the printer. The function requires two parameters, the URL of the XML file and the tagname containing the Base64 encoded text.


Image Printing


Filesystem Printing

Print to local filesystem

   qz.append("foobar\r\n");
   qz.printToFile("/tmp/raw.txt");

Win32 Device Namespace

Some hardware devices -- such as the Bematech Pole Display (previously known as Logic Controls) -- can be installed as a device namespace using the USB driver, e.g. \\.\LCLD9\. This allows Java to bypass the HID interface and send data directly to the device.

Note: If Java displays The handle is invalid, put something after the last backslash, such as dummy

   qz.append("\r\nPlease visit qz.io\r\n");
   qz.printToFile("\\\\.\\LCLD9\\dummy");
Edit this page