How to print raw TSC TSPL/TSPL2 commands from Javascript
Product JSPrintManager Published 05/14/2025 Updated 11/05/2026 Author Neodynamic
Overview
TSPL (TSC Printer Language) commands are a set of instructions used to control a thermal label printer, enabling the creation of various types of labels and other printed materials. These commands are used to define the layout, text, graphics, and other elements of the label.
Basic TSPL commands for some printing elements include:
- SIZE: Set the size of the label in inch unit.
- PRINT: Prints the label n times/copies.
- TEXT: Prints text on the label, allowing for font selection, size, and position control.
- BARCODE: Prints various types of 1D and 2D barcodes, including their type, size, and position.
- QRCODE: Prints QR codes, allowing for encoding data within a label.
- BITMAP: Prints bitmap images, enabling the inclusion of graphics on labels.
- IMAGE: Another command for printing images, often used in conjunction with the BITMAP command.
TSC TSPL/TSPL2 commands are very simple and text plain! The main advantage of using raw TSC TSPL/TSPL2 commands for printing instead of using the built-in browser javascript printing (window.print();) is that the printing performance will be way faster; a factor that is key in the aforementioned scenarios. No matter which Web Platform/Framework you use (ASP.NET, PHP, Django, Ruby On Rails (RoR), Express.js, AngularJS/SPA, etc.), you'll be able to use raw printing feature with the help of our JSPrintManager solution that was specially designed for this kind of printing needs.
In this walkthrough, you'll learn how to print raw TSC TSPL/TSPL2 commands from Javascript directly to the client printer without displaying a print dialog at all. You'll be able to print TSC TSPL/TSPL2 commands to the Default client printer as well as to any other installed printer at the client machine. This solution works with any popular browser like Chrome, Edge, Firefox & Safari on Windows, Linux, Raspberry Pi and Mac systems!
The TSC TSPL/TSPL2 commands that we'll use in this article will print out a text and a barcode that will look like this:

A Sample label printed from Javascript and created by using TSC TSPL/TSPL2 commands
Step-by-step
- Be sure you install in your dev machine JSPrintManager (JSPM) (Available for Windows, Linux, Raspberry Pi & Mac)
This small app must be installed on each client that will print from your website!
Since Chrome 142, browsers ask the user to allow Local Network Access the first time your website connects to the JSPrintManager App. - By using your favorite Web Development IDE or Text Editor, create a new HTML file like index.html
Copy/paste the following code snippets:HTML Code
<div style="text-align:center"> <h1>Print TSC TSPL/TSPL2 commands from Javascript</h1> <hr /> <label for="printerType">Client printer:</label> <select id="printerType" onchange="showPrinterSettings();"> <option value="0">Default printer</option> <option value="1">Let the user select it (OS print dialog)</option> <option value="2" selected>Installed printer</option> <option value="3">IP/Ethernet printer</option> <option value="4">Parallel port (LPT) printer</option> <option value="5">Serial port (RS-232) printer</option> <option value="6">Bluetooth printer</option> </select> <div id="printer-settings-2" class="printer-settings"> <label>Installed printer: <select id="installedPrinterName"></select></label> </div> <div id="printer-settings-3" class="printer-settings" style="display:none"> <label>IP address: <input id="netIp" value="10.0.0.1" /></label> <label>Port: <input id="netPort" value="9100" /></label> <label>or DNS name: <input id="netDns" /></label> </div> <div id="printer-settings-4" class="printer-settings" style="display:none"> <label>Parallel port: <input id="lptPort" value="LPT1" /></label> </div> <div id="printer-settings-5" class="printer-settings" style="display:none"> <label>Serial port: <select id="serialPort"></select></label> <label>Baud rate: <input id="serialBaudRate" value="9600" /></label> <label>Data bits: <select id="serialDataBits"> <option value="Eight">8</option> <option value="Seven">7</option> <option value="Six">6</option> <option value="Five">5</option> </select> </label> <label>Parity: <select id="serialParity"> <option>None</option> <option>Odd</option> <option>Even</option> <option>Mark</option> <option>Space</option> </select> </label> <label>Stop bits: <select id="serialStopBits"> <option value="One">1</option> <option value="OnePointFive">1.5</option> <option value="Two">2</option> </select> </label> <label>Flow control: <select id="serialFlowControl"> <option value="None">None</option> <option value="XOnXOff">XOn/XOff</option> <option value="RequestToSend">RTS (Request to send)</option> <option value="RequestToSendXOnXOff">RTS + XOn/XOff</option> </select> </label> </div> <div id="printer-settings-6" class="printer-settings" style="display:none"> <label>Bluetooth address: <input id="btAddress" placeholder="00:00:00:00:00:00" /></label> <label>Channel: <input id="btChannel" value="1" /></label> </div> <br /><br /> <button type="button" onclick="doPrinting();">Print Now...</button> </div>Script References
- Download JSPrintManager.js
- Copy all of these *.js files to the same folder where your html page is located and then add the following script references to your page.
<!-- JSPrintManager.js (download it or install it with: npm install jsprintmanager) --> <script src="JSPrintManager.js"></script>Script Code
<script> // Start the connection with the JSPrintManager Client App JSPM.JSPrintManager.auto_reconnect = true; JSPM.JSPrintManager.start(); JSPM.JSPrintManager.WS.onStatusChanged = function () { if (jspmWSStatus()) { // get the client installed printers JSPM.JSPrintManager.getPrinters().then(function (printersList) { fillSelect('installedPrinterName', printersList); }); // get the client serial ports (if any) JSPM.JSPrintManager.getSerialPorts().then(function (portsList) { fillSelect('serialPort', portsList); }); } }; // Do printing... function doPrinting() { if (jspmWSStatus()) { // Create a ClientPrintJob var cpj = new JSPM.ClientPrintJob(); // Set the target client printer cpj.clientPrinter = getClientPrinter(); // Set the raw printer commands // TSC TSPL/TSPL2 commands for a sample label var lineFeed = "\r\n"; var cmds = ''; cmds += "SIZE 4,1" + lineFeed; // label size in inches (width, height) cmds += "GAP 0,0" + lineFeed; // gap between labels cmds += "DIRECTION 1" + lineFeed; cmds += "CLS" + lineFeed; // clear the image buffer cmds += "TEXT 10,10, \"2\",0,1,1, \"Code 128\"" + lineFeed; cmds += "BARCODE 10,50, \"128\",100,1,0,2,2, \"123456abcd123456\"" + lineFeed; cmds += "PRINT 1" + lineFeed; // print 1 copy cpj.printerCommands = cmds; // Trace the print job status (optional) traceJob(cpj); // Send the print job to the client printer cpj.sendToClient(); } } // Check the connection status with the JSPrintManager Client App function jspmWSStatus() { var status = JSPM.JSPrintManager.websocket_status; if (status == JSPM.WSStatus.Open) { return true; } else if (status == JSPM.WSStatus.WaitingForUserResponse) { console.info('Waiting for the user to allow this website (JSPrintManager dialog or browser Local Network Access prompt)...'); } else if (status == JSPM.WSStatus.Blocked) { alert('JSPrintManager has blocked this website!'); } else if (status == JSPM.WSStatus.NotInstalled || status == JSPM.WSStatus.Closed) { alert('JSPrintManager Client App is not installed or not running! Download it from https://neodynamic.com/downloads/jspm'); } else if (status == JSPM.WSStatus.CertificateError) { alert('A TLS/SSL certificate error prevented the connection with JSPrintManager Client App.'); } else if (status == JSPM.WSStatus.ConnectionError) { alert('A network error (e.g. a firewall) prevented the connection with JSPrintManager Client App.'); } return false; } // Show the settings of the selected printer type function showPrinterSettings() { var panels = document.querySelectorAll('.printer-settings'); for (var i = 0; i < panels.length; i++) { panels[i].style.display = (panels[i].id == 'printer-settings-' + val('printerType')) ? '' : 'none'; } } // Create the client printer for the selected printer type function getClientPrinter() { switch (val('printerType')) { case '0': return new JSPM.DefaultPrinter(); case '1': return new JSPM.UserSelectedPrinter(); case '2': return new JSPM.InstalledPrinter(val('installedPrinterName')); case '3': return new JSPM.NetworkPrinter(parseInt(val('netPort')), val('netIp'), val('netDns')); case '4': return new JSPM.ParallelPortPrinter(val('lptPort')); case '5': return new JSPM.SerialPortPrinter(val('serialPort'), parseInt(val('serialBaudRate')), JSPM.Serial.Parity[val('serialParity')], JSPM.Serial.StopBits[val('serialStopBits')], JSPM.Serial.DataBits[val('serialDataBits')], JSPM.Serial.Handshake[val('serialFlowControl')]); case '6': return new JSPM.BluetoothPrinter(val('btAddress'), parseInt(val('btChannel'))); } } // Log the print job status updates (optional) function traceJob(cpj) { cpj.onUpdated = function (data) { console.info(data); }; cpj.onFinished = function (data) { console.info(data); }; cpj.onError = function (data, isCritical) { console.error(data); }; } // Helpers function val(id) { return document.getElementById(id).value; } function checked(id) { return document.getElementById(id).checked; } // Fill a <select> element with a list of items function fillSelect(id, items, getText) { var select = document.getElementById(id); select.innerHTML = ''; for (var i = 0; i < items.length; i++) { var text = getText ? getText(items[i]) : items[i]; select.add(new Option(text, text)); } } </script> - That's it! Run your website and test it. Click on Print Now... to print the TSC TSPL/TSPL2 Commands without print dialog. You can print it to the Default client printer, to any installed printer available at the client machine, or directly to an IP/Ethernet, LPT, RS-232 or Bluetooth printer.
NOTE Besides the Default printer and any installed printer, this sample also lets you print through the OS print dialog and directly to an IP/Ethernet printer (e.g. port 9100), a Parallel Port (LPT), a Serial Port (RS-232) or a Bluetooth printer.
Useful? Share it!
| Tweet |
|
Related Articles
How to print raw Zebra ZPL commands from JavascriptHow to print raw Zebra EPL commands from Javascript
How to configure RAW printing mode in Windows
How to configure RAW printing mode in Linux and Raspberry Pi
Need help? Contact Support
We provide best-in-class customer service and support directly from members of our dev team! If we are available when you contact us, you will get a response in few minutes; otherwise the maximum turnaround is 24hs in most cases.