<script src="https://labeldictate.com/text2barcode/lib/t2bprinter.js"></script>
Obtains a list of all available printers connected to the device, allowing them to be later managed or selected for printing operations.
const available = await T2bPrinter.available() for (const printer of available.printer) { console.debug("printer", JSON.stringify(printer, null, 1)) }
{ "printer":[ { "uid":"ZDesigner GK420t Plus (ZPL)", "name":"ZDesigner GK420t Plus (ZPL)", "manufacturer":"Zebra Technologies" "connection":"driver", "deviceType":"printer", "version":4 }, { ... } ] }
Gets the device's default printer
const printer = await T2bPrinter.default() console.debug("defaultPrinter:", JSON.stringify(printer, null, 1))
{ "uid":"ZDesigner GK420t Plus (ZPL)", "name":"ZDesigner GK420t Plus (ZPL)", "manufacturer":"Zebra Technologies", "connection":"driver", "deviceType":"printer", "version":4 }
Gets printers that meet a specified search criteria.
const printers = await T2bPrinter.filter(it => it.name.includes("ZPL")) console.debug("printers:", JSON.stringify(printers, null, 1))
[ { "uid":"ZDesigner GK420t Plus (ZPL)", "name":"ZDesigner GK420t Plus (ZPL)", "manufacturer":"Zebra Technologies" "connection":"driver", "deviceType":"printer", "version":4 }, { ... } ]
Gets a printer that meets a specified search criteria.
const printer = await T2bPrinter.find(it => it.uid == "Designer GK420t Plus (ZPL)") console.debug("printer:", JSON.stringify(printer, null, 1))
{ "uid":"ZDesigner GK420t Plus (ZPL)", "name":"ZDesigner GK420t Plus (ZPL)", "manufacturer":"Zebra Technologies", "connection":"driver", "deviceType":"printer", "version":4 }
Print zpl to a given printer
const result = await T2bPrinter.write(printer, ` ^XA ^PW609 ^LL403 ^PON ^CI28 ^FO38,30^GB545,349,5^FS ^FO85,60^A0N,33,33^FH^FDZPL PRINT TEST - 3"^FS ^FO170,100^A0N,33,33^FH^FD$ Dollar - € Euro^FS ^FO170,130^A0N,33,33^FH^FDL Lambda - ¥ Yen^FS ^FO150,180^A0N,33,33^FH^FDSpecial characters: ^FS ^FO150,210^A0N,33,33^FH^FDñ á é í ó ú characters^FS ^BY2,2,44^FO90,280^BCN,,Y,N ^FD123456789012^FS ^FO465,20^BQN,2,4 ^FH\^FDLA,123456789012^FS ^PQ1,0,1,Y ^XZ `); console.debug("write", JSON.stringify(result, null, 1))
{ "result": true, "message": "messages" }
Print to a given printer
cont const blob = new Blob([zpl], { type: "application/octet-stream" }); const result = await T2bPrinter.writeAsBlob(printer, blob); console.debug("writeAsBlob", JSON.stringify(result, null, 1))
{ "result": true, "message": "messages" }
Converts an image or PDF into ZPL or another supported format, and optionally prints it.
const fileInput = document.querySelector('#file'); const resource = fileInput.files[0]; // Blob const payload = { options: { action: "print", // or "return", "store" fromFormat: "png", // "jpg", "pdf" toFormat: "zpl", // "zpl", "esc-pos", "tspl" resize: { width: 600 }, dithering: "FloydSteinbergDithering" }, device: { uid: "ZDesigner GK420t Plus (ZPL)", name: "ZDesigner GK420t Plus (ZPL)", manufacturer: "Zebra Technologies", connection: "driver", deviceType: "printer", version: 4 } }; const result = await T2bPrinter.convert(resource, payload); console.debug("converted", JSON.stringify(result, null, 1));
{ "data": "base64-encoded ZPL or format", "width": 600, "height": 400, "filename": "converted.zpl" }