Wiki - 1.9 PostScript Printing


The following code can be used for PostScript Printing only. If you are unsure what PostScript Printing is, please refer to What is PostScript Printing?

Note: Printing via these methods will require a PostScript, or 2d/image/pixel-based queue and driver/kernel module. The manufacturer's driver will usually support this type of printing.

If your printer is set up as a generic/raw-text printer, these printing methods will not work.

While some drivers, such as Zebra's ZDesigner driver for Microsoft Windows, will support both raw and PostScript printing in one queue, this is not the case across all operating systems. If using CUPS (Mac OS X and Linux), you will need separate drivers/kernel modules for raw and PostScript printing. Please inquire at with any questions or concerns.

###HTML Printing

  1. QZ Print can print advanced HTML components by rendering an HTML component to an image using the html2canvas jQuery plugin (bundled in the /dist/js folder).

    <body id="content" bgcolor="#FFF380"> ... 
    <canvas id="hidden_screenshot" style="display:none;" /> ...
    // JavaScript (jQuery)
             canvas: hidden_screenshot,
             onrendered: function() {

Note: HTML id #content can be virtually any HTML component. HTML id hidden_screenshot is a temporary place to draw the content and should be set display=none to prevent the render from becoming visiable.

  1. QZ Print has the ability to print basic HTML components to a PostScript style printer directly from the browser. (PostScript printers include all major LaserJet, DeskJet, PSC, Home Printers, etc). Mileage may vary across different operating systems. Please file a bug report using ISSUES link above if you encounter issues.

    // Basic HTML Printing
    qz.appendHTML("<html><h1><font color=Red>Hello world!</font></h1>qz-print HTML Printing Demo</html>");
    // Printing using extra spaces, fixed font, dashes
    var text = "*no-line-break*       Hello from ’qz-print’       *no-line-break*";
    // Fix whitespace and special character behavior
    text = text.replace(/ /g, "&nbsp;").replace(//g, "'").replace(/-/g,"&#8209;");      
    qz.appendHTML('<html><table border=1 style="font-size:10pt; font-face:\'Courier New\';"><tr><td>' + text + '</td></tr></table></html>');
    // Printing an existing HTML file
    // Wait for append to finish
    function qzDoneAppending() {

 > **Linux HTML Printing:** There is a bug preventing margins from working properly on Linux:


###PDF Printing

QZ Print allows printing PDF files directly to a printer. This functionality is experimental and uses a 3rd party renderer "PDF-RENDERER". 

   // Make sure pdf-renderer.jar is in the "./lib" folder
   // Append the PDF
   qz.appendPDF(window.location.href + "/../sample.pdf");

   function qzDoneAppending() {
      // Very important for PDFs, use "printPS()" instead of "print()"

###Base64 PDF Printing

// Must start with "data:application/pdf;base64,XXXXXXXXXX"

function qzDoneAppending() {
   // Very important for PDFs, use "printPS()" instead of "print()"

CUPS/Linux PDF Printing: Please note, there is a bug preventing margins from working properly on some versions of CUPS:

###Image Printing

Experimental support for appending printer-specific images by url and/or Base64.

// DeskJet/LaserJet, etc (don't mix with raw devices)
// Paper size/orientation since version 1.4.5
qz.setPaperSize("210mm", "297mm");  // A4
// qz.setPaperSize("8.5in", "11.0in");  // US Letter
qz.setAutoSize(true);               // Preserve proportions
qz.setOrientation("landscape");     // Default is "portrait"
qz.appendImage("image.png");        // Append our image.  Note: Wait for this to finish, or implement   "jzebraDoneAppending()"

Edit this page