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

2.0 Raw Printing

Tres Finocchiaro edited this page Jan 15, 2016 · 51 revisions

###Compatibility

Product Version Applies Notes
QZ Tray 2.0 ✅ Yes
QZ Tray 1.9 🚫 No See 1.9 Raw Printing
QZ Print 1.9 🚫 No See 1.9 Raw Printing

💡 Note: To see if a product or version is end of life see product roadmap.

###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?

Languages

Techniques

Advanced

Generic

Boilerplate code to send raw commands to any printer. See also ZPL, EPL, ESC/P for specific examples. If your raw language is missing, please contact support.

function printStuff() {
   var config = qz.configs.create("Printer Name");

   var data = [
      'Raw Data\n',
      'More Raw Data\n',
      'Even More Raw Data\n'
   ];

   qz.print(config, data).catch(function(e) { console.error(e); });
}

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

  • Albeit obvious, each example needs a trigger, such as a button, .e.g.
<input type="button" onclick="printStuff()" value="Print"></input>

ZPL

Example for sending raw ZPL commands to a printer

Note: language: "foo" is only required if providing a raw image type in the data stream.

function printZPL() {
   var config = qz.configs.create("Printer Name", { language: "zpl" });

   var data = [
      '^XA\n',
      '^FO50,50^ADN,36,20^FDPRINTED USING QZ PRINT PLUGIN\n',
      { type: 'raw', format: 'visual', data: 'assets/img/image_sample_bw.png' },
      '^FS\n',
      '^XZ\n'
   ];

   qz.print(config, data).catch(function(e) { console.error(e); });
}

EPL

Example for sending EPL commands to a printer.

Note: language: "foo" is only required if providing a raw image type in the data stream.

function printEPL() {
   var config = qz.configs.create("Printer Name", { language: "epl" });
   
   var data = [
      '\nN\n',
      { type: 'raw', format: 'visual', data: 'assets/img/image_sample_bw.png', options: { x: 20, y: 0 } },
      '\nP1,1\n'
   ];

   qz.print(config, data).catch(function(e) { console.error(e); });
}

ESC/P

function printESCP() {
   var config = qz.configs.create("Printer Name", { language: "escp" });

   var data = [
      {
         type: 'raw', 
         format: 'visual', 
         data: 'assets/img/image_sample_bw.png', 
         options: { dotDensity: 'double' }
      },
      {
         type: 'raw',
         data: '\nPrinted using qz-print plugin.\n\n\n\n\n\n'
      }
   ];

   qz.print(config, data).catch(function(e) { console.error(e); });
}

Base64

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

function printBase64() {
   var config = qz.configs.create("Printer Name");

   var data = [
      {
         type: 'raw',
         format: 'base64',
         data: 'Ck4KcTYwOQpRMjAzLDI2CkI1LDI2LDAsMUEsMyw3LDE1MixCLCIxMjM0IgpBMzEwLDI2LDAsMywx' +
            'LDEsTiwiU0tVIDAwMDAwIE1GRyAwMDAwIgpBMzEwLDU2LDAsMywxLDEsTiwiUVogUFJJTlQgQVBQ' +
            'TEVUIgpBMzEwLDg2LDAsMywxLDEsTiwiVEVTVCBQUklOVCBTVUNDRVNTRlVMIgpBMzEwLDExNiww'
      }
   ];

   qz.print(config, data).catch(function(e) { console.error(e); });
}

File

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

function printFile() {
   var config = qz.configs.create("Printer Name");

   var data = [
      {
         type: 'raw', 
         format: 'file', 
         data: 'assets/raw-data.txt'
      }
   ];
  
   qz.print(config, data).catch(function(e) { console.error(e); });
}

XML

The ability to read the contents of an XML file containing Base64 encoded commands and send these commands to the printer.

  1. Set the format to xml:
  • format: 'xml'
  1. Then add the xmlTag:
  • options: { xmlTag: 'v7:Image' }
    function printXML() {
       var config = qz.configs.create("Printer Name");
    
       var data = [
          {
             type: 'raw', 
             format: 'xml', 
             data: 'assets/zpl_sample.xml', 
             options: { xmlTag: 'v7:Image' }
          }
       ];
    
       qz.print(config, data).catch(function(e) { console.error(e); });
     }

Filesystem

Print to local filesystem

function printToFile() {
   var config = qz.configs.create({ file: "/path/to/output.txt" }); // or "C:\path\to\output.text", etc

   var data = [
      'Raw Data\n',
      'More Raw Data\n',
      'Even More Raw Data\n'
   ];

   qz.print(config, data).catch(function(e) { console.error(e); });
}

Advanced Print Spooling

Spools jobs between specified endOfDoc delimiter. Useful for avoiding buffer overflows on unusually large quantity print jobs by spooling each raw job individually. Defaults to 1 job per spool, but can be overridden using perSpool option.

function advancedSpooling() {
   var config = qz.configs.create("Printer Name", { endOfDoc : '\n' });

   var data = [
      'First\n',
      'Second\n',
      'Third\n'
   ];

   qz.print(config, data).catch(function(e) { console.error(e); });
}