-
Notifications
You must be signed in to change notification settings - Fork 101
PostScript Printing
#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?
###Print to File
Since version 1.1.9, qz-print allows printing to a physical file. This is useful for bypassing printer drivers completely and sending raw data to a remote Windows Print Server queue, i.e. \server\printer. (Thanks André T)
function printToFile() {
// Append some data
qz.append("A37,503,0,1,2,3,N,ABC WIDGET CO\n");
// Note, the doubly escaped forward slashes!
qz.printToFile("\\\\server\\printer")
}
###HTML Printing
- Since version 1.4.5, 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).
// HTML
<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.
- Since version 1.3.2, 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, " ").replace(/’/g, "'").replace(/-/g,"‑");
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
while (!qz.isDoneAppending()) { // wait }
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
Since version 1.1.9, qz-print allows printing PDF files directly to a printer. This functionality is experimental and uses a 3rd party renderer "PDF-RENDERER".
Note: This feature will not work with many raw printing devices, such as Zebra, Epson, Citizen printers. The data is sent in PostScript format, which is more common for LaserJet printers. USE WITH CAUTION!
function printPDF() {
// Make sure pdf-renderer.jar is in the "./lib" folder
// Append the PDF
qz.appendPDF(window.location.href + "/../sample.pdf");
// 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
###Printing Images
Experimental support for appending printer-specific images by url and/or Base64.
// *Note 1: Applet will append special raw markup, i.e. ^GFA, char(27), etc
// *Note 2: Image width and image height must be divisible by 8
// *Note 3: Newline/Carriage Return must be appended manually
// *Note 4: Images should be strictly black and white
// Zebra (EPL):
qz.appendImage("image.png", "EPL");
while (!qz.isDoneAppending()) {} // wait
qz.append("\r\n");
// Zebra (ZPLII):
qz.appendImage("image.png", "ZPLII");
while (!qz.isDoneAppending()) {} // wait
qz.append("\r\n");
// Zebra (CPCL):
qz.appendImage("image.png", "CPCL");
while (!qz.isDoneAppending()) {} // wait
qz.append("\r\n");
// Epson (ESCP):
qz.appendImage("image.png", "ESCP");
while (!qz.isDoneAppending()) {} // wait
qz.append("\r\n");
// Base64
qz.appendImage("data:image/png;base64,AAAAAAAAA...", "ZPLII");
qz.append("\n");
// 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.print();