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 Jan 28, 2016 · 41 revisions

Compatibility

  • ✅ 2.0 | ⛔ 1.9 | ...

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 printData = [
        {
            type: 'html',
            format: 'plain',
            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 printData = [
        {
            type: 'html',
            format: 'plain',
            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. We use a 3rd party renderer PDF Box 2.0

Note: This feature will 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 printers.

  1. How to print a PDF file

    var config = qz.configs.create("Printer Name");
    var data = [
       { 
          type: 'pdf', 
          data: getPath() + '/assets/pdf_sample.pdf' 
       }
    ];
    qz.print(config, data).catch(function(e) { console.error(e); });
  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 Image Printing

Image Interpolation

An 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); });