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

1.9 PostScript Printing

klabarge edited this page Sep 7, 2016 · 8 revisions

Compatibility

  • ⛔ 2.x | ✅ 1.9 | ...

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 support@qz.io 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)
    $("#content").html2canvas({ 
             canvas: hidden_screenshot,
             onrendered: function() {
                qz.append64($("canvas")[0].toDataURL('image/png'));
                qz.printPS();
             }
        });

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>");
    qz.printHTML();
    
    // 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>');
    
    qz.printHTML();
    
    // Printing an existing HTML file
    qz.appendHTMLFile("../form.html");
    
    // Wait for append to finish
    function qzDoneAppending() {
        qz.printHTML();
    }

 > **Linux HTML Printing:** There is a bug preventing margins from working properly on Linux: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6726691

***

###PDF Printing

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



   ```js
   // 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()"
      qz.printPS();
   }

###Base64 PDF Printing

// Must start with "data:application/pdf;base64,XXXXXXXXXX"
qz.appendPDF("data:application/pdf;base64,dGVzdA[...]==");

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

CUPS/Linux PDF Printing: Please note, there is a bug preventing margins from working properly on some versions of CUPS: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6726691


###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()"
qz.printPS();