-
Notifications
You must be signed in to change notification settings - Fork 101
2.0 Pixel Printing
- ✅ 2.0 | ⛔ 1.9 | ...
- 💡 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 printers. The
ZDesigner
driver from Zebra allows both raw and pixel printing.
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 rendering is done via pure Java in using an embedded webkit browser
var config = qz.configs.create("Printer Name"); var data = [ { type: 'html', format: 'plain', data: 'assets/html_sample.html' } ]; qz.print(config, data).catch(function(e) { console.error(e); });
-
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: 'plain', data: 'assets/html_sample.html', options: { margins: 2, orientation: 'landscape', printerTray: 2 } } ]; qz.print(config, data).catch(function(e) { console.error(e); });
⚠️ Java 8 + JavaFX is required for high-resolution (>72 dpi) HTML printing.⚠️ By default, JavaFX is NOT included in OpenJDK- 💡 Older Ubuntu versions can get Oracle Java 8 + JavaFX here: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html
QZ Tray 2.0 allows printing PDF files directly to a printer using Apache PDFBOX.
-
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); });
-
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); });
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); });
A page size can be set using the config parameter size
.
Custom page sizes are not supported. When a page size is set, the closest matching page size available to the printer (determined by the printer driver) is selected.
- To print to the wider edge (standard page sizes are expected), the
orientation
parameter can be used to set orientation tolandscape
- Both standard and metric sizes are supported, but it is highly recommended to use inches (standard). This is do to the
density
that is in DPI (dots per inch).
function printStuff() {
var config = qz.configs.create("Printer Name", { units: "in", orientation: "landscape", size: { width: 2, height: 5} )};
var data = [
'Raw Data\n',
'More Raw Data\n',
'Even More Raw Data\n'
];
qz.print(config, data).catch(function(e) { console.error(e); });
}
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); });
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); });
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); });