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

1.9 Raw Printing

Tres Finocchiaro edited this page Mar 12, 2018 · 3 revisions

Compatibility

  • ⛔ 2.x | ✅ 1.9 | ...

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

  3. 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.

  • qz.setEndOfDocument("..."); : Mark the end of a label, in the case of EPL, P1\n. qz knows to look for the end of a label and treat this as the end of a "page" for better control of larger spooled jobs (i.e. 50+ labels).

  • qz.setDocumentsPerSpool("10"); : The amount of labels to spool to the printer at a time. When qz counts this many EndOfDocument's, a new print job will automatically be spooled to the printer and counting will start over.

    function print() {
       qz.setEndOfDocument("P1\n");    // EPL
       // qz.setEndOfDocument("^XZ\n");   // ZPL
       qz.setDocumentsPerSpool("10");      
    
       // Send characters/raw commands to printer
       qz.print();
    }

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 [email protected]
// 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.

  • Using qz-print's appendFile() function, a file containg your raw EPL/ZPL can be sent directly to the printer.

  • Example:

    qz.appendFile("http://yoursite/zpllabel.txt"); // ...etc */
    
    qz.appendFile(window.location.href + "/../zpl.txt");
    
    function qzDoneAppending() {
          qz.print();
    }

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.

  • Appends the contents of an XML file from a SOAP response, etc.

  • a valid relative URL or a valid complete URL is required for the XML file.

  • The second parameter must be a valid XML tag/node containing base64 encoded data.

    • i.e. <node_1>aGVsbG8gd29ybGQ=</node_1>
  • Example:

    qz.appendXML("http://yoursite.com/zpl.xml", "node_1"); 
    qz.appendXML("C:\\zpl.xml", "v7:Image");
    
    function printXML() {
       // Send characters/raw commands to printer
       qz.print();
    }

Image Printing

  • Applet will append special raw markup, i.e. ^GFA, char(27), etc

  • Image width and image height must be divisible by 8

  • Newline/Carriage Return must be appended manually

  • Images should be strictly black and white

    // Zebra (EPL):   WARNING:  Asynchronous, see qzDoneAppending() below.
    qz.appendImage("image.png", "EPL", 150, 300);    // location x = 150, y = 300
    
    // Zebra (ZPLII): WARNING:  Asynchronous, see qzDoneAppending() below.
    qz.appendImage("image.png", "ZPLII");  
    
    // Zebra (CPCL):  WARNING:  Asynchronous, see qzDoneAppending() below.
    qz.appendImage("image.png", "CPCL");
    
    // Epson (ESCP):  WARNING:  Asynchronous, see qzDoneAppending() below.
    qz.appendImage("image.png", "ESCP", "single");   // "single" or "double" sets Epson pixel density
    
    // Base64         WARNING:  Asynchronous, see qzDoneAppending() below.
    qz.appendImage("data:image/png;base64,AAAAAAAAA...", "ZPLII");
    
    // Fired automatically when appendImage() is called
    function qzDoneAppending() {
        // The remaining data (end of label, etc)
        qz.append("\r\n");
        qz.append( ... );
    }

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");