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

2.0 Pixel Printing

Tres Finocchiaro edited this page Mar 12, 2016 · 41 revisions

Compatibility

  • ✅ 2.0 | ⛔ 1.9 | ...

Background

These features may not work with many raw printing devices, such as Zebra, Epson, Citizen printers. The data is sent in Pixel Printing format, which is more common for LaserJet or Deskjet printers. The ZDesigner driver from Zebra allows both raw and pixel printing.

To test these features without a physical printer, try using a PDF or XPS writer.

Contents

The following code can be used for Pixel Printing (formerly Postscript Printing) only. If you are unsure what Pixel Printing is, please refer to What is Pixel Printing?


HTML Printing

  1. HTML rendering is done via pure Java in using an embedded webkit browser

    var config = qz.configs.create("Printer Name");
    var data = [
        {
            type: 'html',
            format: 'file', // or 'plain' if the data is raw HTML
            data: 'assets/html_sample.html'
        }
    ];
    qz.print(config, data).catch(function(e) { console.error(e); });
  2. An options parameter can be supplied to to signify things including margins, orientation, size, printer language, encoding, etc.

    var config = qz.configs.create("Printer Name");
    var data = [
        {
            type: 'html',
            format: 'file', // or 'plain' if the data is raw HTML
            data: 'assets/html_sample.html',
            options: { margins: 2, orientation: 'landscape', printerTray: 2 }
        }
    ];
    qz.print(config, data).catch(function(e) { console.error(e); });

    JavaFX

PDF Printing

QZ Tray 2.0 allows printing PDF files directly to a printer using Apache PDFBOX.

  • ⚠️ Warning: Mac users may need to specify a density per #155
  1. How to print a PDF file

    var config = qz.configs.create("Printer Name");
    var data = [
       { 
          type: 'pdf', 
          data: 'assets/pdf_sample.pdf' 
       }
    ];
    qz.print(config, data).catch(function(e) { console.error(e); });

    Base64

  2. How to print a base64 PDF

    var config = qz.configs.create("Printer Name");
    var data = [
       { 
          type: 'pdf',
          format: 'base64',
          data: 'Ck4KcTYwOQpRMjAzLDI2CkI1LDI2LDAsMUEsMyw3LDE1MixCLCIxMjM0IgpBMzEwLDI2LDAsMywx...' 
       }
    ];
    qz.print(config, data).catch(function(e) { console.error(e); });

Image Printing

var config = qz.configs.create("Printer Name");
var data = [
   { 
      type: 'image', 
      data: 'assets/img/image_sample.png' 
   }
];
qz.print(config, data).catch(function(e) { console.error(e); });

Advanced Printing

Page Size

A page size can be set using the config parameter size.

  • Both standard and metric sizes are supported. Warning, providing a metric page size will assume the density is in a metric format as well.
Dymo LabelWriter

The following example illustrates how to print a 2.25in x 1.25in label to a Dymo LabelWriter printer.

  • size is provided in inches. Alternatively 57.15mm x 31.75mm can be provided if metric units are desired.
  • interpolation is provided to prevent barcode blurring.
  • colorType is provided to maximize driver quality compatibility/300dpi dithering.
function printStuff() {
   var config = qz.configs.create("Printer Name", {
      size: {width: 2.25, height: 1.25}, units: 'in', 
      colorType: 'grayscale', 
      interpolation: "nearest-neighbor" 
   });

   var data = [
      { 
         type: 'image', 
         data: 'assets/img/image_sample.png' 
      }
   ];

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

Image Interpolation

A config parameter interpolation can be provided to change the pixel blending technique used when scaling an image.

var config = qz.configs.create("Printer Name", { interpolation: "nearest-neighbor" });
var data = [
   { 
      type: 'image', 
      data: 'assets/img/image_sample.png' 
   }
];
qz.print(config, data).catch(function(e) { console.error(e); });

Density

Not providing a density will cause printing to use the default value for the printer. A config parameter density can be provided to change the DPI, dots/mm or dots/cm respectively.

var config = qz.configs.create("Printer Name", { units: "in", density: "600" });  // force 600dpi
var data = [
   { 
      type: 'pdf', 
      data: 'assets/pdf_sample.pdf' 
   }
];
qz.print(config, data).catch(function(e) { console.error(e); });

Custom Job Name

A config parameter jobName can be provided to change the name listed in the print queue.

var config = qz.configs.create("Printer Name", { jobName: "Receipt #123456" });
var data = [
   { 
      type: 'image', 
      data: 'assets/img/image_sample.png' 
   }
];
qz.print(config, data).catch(function(e) { console.error(e); });

Chaining Requests

Print requests can be chained together to print several documents at once, or to print to several different printers.

var config = qz.configs.create("Printer Name");
var data = [{ type: 'image', data: null, }];

data.data = 'assets/img/my_first_image.png';
qz.print(config, data)              // First document

.then(function() {
   data.data = 'assets/img/my_second_image.png';
   return qz.print(config, data);   // Second document
})

.then(function() {
   data.data = 'assets/img/my_third_image.png';
   return qz.print(config, data);   // Second document
})

.catch(function(e) {
   console.error(e);                // Exceptions throw all the way up the stack
});