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

Raw Printing

Tres Finocchiaro edited this page Jul 9, 2015 · 37 revisions

#Raw Printing

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.

function print() {

   /*
   Mark the end of a label, in this case  P1 plus a newline character
   qz-printknows to look for this and treat this as the end of a "page"
   for better control of larger spooled jobs (i.e. 50+ labels)
   */
   qz.setEndOfDocument("P1\n");
        
   /*
   The amount of labels to spool to the printer at a time. When
   qz-print counts this many `EndOfDocument`'s, a new print job will 
   automatically be spooled to the printer and counting will start
   over.
   */
   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.

function printFile() {
   if (qz != null) {
   /* 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");
      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.

function printXML() {
   // 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");

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

###Image Printing

// *Note 1:  Applet will append special raw markup, i.e. ^GFA, char(27), etc
// *Note 2:  Image width and image height must be divisible by 8
// *Note 3:  Newline/Carriage Return must be appended manually
// *Note 4:  Images should be strictly black and white

// Zebra (EPL):   WARNING:  Asynchronous, see qzDoneAppending() below.
qz.appendImage("image.png", "EPL");

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

// 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( ... );
}