This documentation provides examples and instructions on how to use the Text2Barcode Web Print API for printing labels using ZPL and ESC/POS commands.
The Text2Barcode Web Print API allows you to print labels directly from your web application to supported printers using ZPL (Zebra Programming Language) and ESC/POS (Epson Standard Code for Printers). This documentation provides sample code and instructions to help you get started.
This example demonstrates how to print a sample label using ZPL (Zebra Programming Language).
<!DOCTYPE html> <html> <head> <!-- Include the t2bprinter.js library necessary to handle the printer --> <script src="https://labeldictate.com/text2barcode/lib/t2bprinter.js"></script> <script> // Asynchronous function that handles printing a label const printLabel = async () => { // Target printer name const printerName = "Zebra GK420d"; // ZPL content of the label to be printed const labelContent = ` ^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 `; try { // Find the printer by its name const printer = await T2bPrinter.find(it => it.name == printerName); // If the printer is found, send the ZPL content to print if (printer) { const result = await T2bPrinter.write(printer, labelContent); // Display the print result in the console alert(JSON.stringify(result, null, 1)); } else { // If the printer is not found, display an error in the console alert(`Printer "${printerName}" not found.`); } } catch (error) { // Handle any errors that occur during the print process alert(error); } } // Call the function to print the label when the page loads printLabel(); </script> </head> <body> <!-- The body of the page is empty as all logic is in the script --> </body> </html>
This code initializes the printer connection, sends the ZPL code to the printer, and prints the label. Ensure that the printer name matches the connected printer's name.
This example demonstrates how to print a sample label using ESC/POS (Epson Standard Code for Printers).
<!DOCTYPE html> <html> <head> <!-- Include the t2bprinter.js library necessary to handle the printer --> <script src="https://labeldictate.com/text2barcode/lib/t2bprinter.js"></script> <script> // Asynchronous function that handles printing a label const printLabel = async () => { // Target printer name const printerName = "Bixolon SRP-330II"; // ESC/POS content of the label to be printed const labelContent = ` <EscPos> <Init/> <QrCode justification="right">QR Test Text</QrCode> <Feed lines="1"/> <BarCode>1234567890</BarCode> <Feed lines="1"/> <Text fontWidth="3" fontHeight="3">Large Text</Text> <Text fontWidth="2" fontHeight="2">Medium Text</Text> <Text fontWidth="1" fontHeight="1">Small Text</Text> <Feed lines="1"/> <Text justification="left">Left</Text> <Text justification="center">Center</Text> <Text justification="right">Right</Text> <Feed lines="1"/> <Text underline="one-dot-thick">Underline</Text> <Text bold="true">Bold</Text> <Text inverse="true">Inverted</Text> <Feed lines="3" /> <Cut mode="full" /> </EscPos> `; try { // Find the printer by its name const printer = await T2bPrinter.find(it => it.name == printerName); // If the printer is found, send the ESC/POS content to print if (printer) { const result = await T2bPrinter.write(printer, labelContent); // Display the print result in the console alert(JSON.stringify(result, null, 1)); } else { // If the printer is not found, display an error in the console alert(`Printer "${printerName}" not found.`); } } catch (error) { // Handle any errors that occur during the print process alert(error); } } // Call the function to print the label when the page loads printLabel(); </script> </head> <body> <!-- The body of the page is empty as all logic is in the script --> </body> </html>
This code initializes the printer connection, sends the ESC/POS code to the printer, and prints the label. Ensure that the printer name matches the connected printer's name.