Documentation
Data Filtering
- ✅ 2.2 | ✅ 2.1 | ⛔ 2.0 | ⛔ 1.9 | ...
- Use
siftlibrary to filter/block unwanted MAC addresses, network adapters, and printers.
-
Must be using QZ Tray 2.1 or later
-
Download and include
sift.jsNote: Optionally, you may
npm install qz-sift<script type="text/javascript" src="path/to/sift.js"></script>
- Printer Details
- Basic Syntax
- Identify/Filter
Note: The sift.js library is not needed for this.
You can get various printer information (driver, densities, default printer, trays) for system attached printers
qz.printers.details();The result is returned as an object array
function detailPrinters() {
qz.printers.details().then(function(data) {
for(var i = 0; i < data.length; i++) {
console.log(data[i].name + " " + data[i].driver + " " + data[i].density + " " + data[i].trays);
}
}).catch(function(e) { console.error(e); });
}Remove whatever matches the option from the data object
sift.toss(data, { option });Keep whatever matches the option criteria from the data object
sift.keep(data, { option });Per the sift library:
-
Printers must be supplied in an object array and must contain a printer
nameand printerdriver.[ { name: 'foo', driver: 'bar' }, { ... } ]
QZ Tray has a built-in function qz.printers.details(); that meets this criteria
The sift library can be used to filter out virtual printers. This can be useful for preventing a user from printing, for example, coupons to a PDF printer.
- Return only the physical printers
function detailPrinters() {
qz.printers.details().then(function (data) {
data = sift.keep(data, { physical: true }); //same as sift.toss(data, { physical: false });
console.log(data);
}).catch(function(e) { console.error(e); });
}- Return only the virtual printers
function detailPrinters() {
qz.printers.details().then(function (data) {
data = sift.keep(data, { physical: false }); //same as sift.toss(data, { physical: true });
console.log(data);
}).catch(function(e) { console.error(e); });
}Return only raw printers
function detailPrinters() {
qz.printers.details().then(function (data) {
data = sift.keep(data, { type: 'raw' });
console.log(data);
}).catch(function(e) { console.error(e); });
}| Physical Adapter | Virtual Adapter |
|---|---|
burnedIn: true |
burnedIn: false |
Return only physical adapters
function listNetworkDevices() {
qz.networking.devices().then(function(data) {
data = sift.keep(data, {burnedIn: true });
console.log(data);
}).catch(function(e) { console.error(e); });
}