Text2 Barcode Docs

Web Print API

Quick Start

<script src="https://labeldictate.com/text2barcode/lib/t2bprinter.js"></script>

Available.

Obtains a list of all available printers connected to the device, allowing them to be later managed or selected for printing operations.

Request

const available = await T2bPrinter.available()
for (const printer of available.printer) {
  console.debug("printer", JSON.stringify(printer, null, 1))
}

Response

{ 
  "printer":[ 
    { 
      "uid":"ZDesigner GK420t Plus (ZPL)", 
      "name":"ZDesigner GK420t Plus (ZPL)", 
      "manufacturer":"Zebra Technologies" 
      "connection":"driver",
      "deviceType":"printer", 
      "version":4
    }, 
    {
      ...
    } 
  ] 
}

Default

Gets the device's default printer

Request

const printer = await T2bPrinter.default()
console.debug("defaultPrinter:", JSON.stringify(printer, null, 1))

Response

{ 
  "uid":"ZDesigner GK420t Plus (ZPL)", 
  "name":"ZDesigner GK420t Plus (ZPL)", 
  "manufacturer":"Zebra Technologies",
  "connection":"driver", 
  "deviceType":"printer", 
  "version":4 
}

Filter

Gets printers that meet a specified search criteria.

Request

const printers = await T2bPrinter.filter(it => it.name.includes("ZPL"))
console.debug("printers:", JSON.stringify(printers, null, 1))

Response

[ 
  { 
    "uid":"ZDesigner GK420t Plus (ZPL)", 
    "name":"ZDesigner GK420t Plus (ZPL)", 
    "manufacturer":"Zebra Technologies" 
    "connection":"driver",
    "deviceType":"printer", 
    "version":4
  }, 
  {
    ...
  } 
]

Find

Gets a printer that meets a specified search criteria.

Request

const printer = await T2bPrinter.find(it => it.uid == "Designer GK420t Plus (ZPL)")
console.debug("printer:", JSON.stringify(printer, null, 1))

Response

{ 
  "uid":"ZDesigner GK420t Plus (ZPL)", 
  "name":"ZDesigner GK420t Plus (ZPL)", 
  "manufacturer":"Zebra Technologies",
  "connection":"driver", 
  "deviceType":"printer", 
  "version":4 
}

Write

Print zpl to a given printer

Request

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))  

Response

{ 
  "result": true, 
  "message": "messages" 
}