Printing Libraries

Every ESC/POS library has a network transport, and pointing it here is a one-line change: the host and port of your virtual printer instead of the device on your network.

The examples below all print the same thing; substitute your own port.

python-escpos

from escpos.printer import Network

printer = Network("virtual-printer.online", port=9411)
printer.text("Hello from python-escpos\n")
printer.cut()
printer.close()

Network is the transport to use - not Usb, not Serial, and not File.

node-thermal-printer

const { ThermalPrinter, PrinterTypes } = require('node-thermal-printer');

const printer = new ThermalPrinter({
  type: PrinterTypes.EPSON,
  interface: 'tcp://virtual-printer.online:9411',
});

printer.println('Hello from node-thermal-printer');
printer.cut();
await printer.execute();

escpos-php

use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
use Mike42\Escpos\Printer;

$connector = new NetworkPrintConnector("virtual-printer.online", 9411);
$printer = new Printer($connector);
$printer->text("Hello from escpos-php\n");
$printer->cut();
$printer->close();

ESCPOS.NET

var printer = new ESCPOS_NET.NetworkPrinter(
    new NetworkPrinterSettings
    {
        ConnectionString = "virtual-printer.online:9411"
    });

var e = new ESCPOS_NET.Emitters.EPSON();
printer.Write(e.PrintLine("Hello from ESCPOS.NET"), e.FullCut());

If nothing arrives

Libraries differ in when they flush and whether they close the connection. A document is finalized when the socket closes or after a short idle timeout, so a library that keeps the connection open produces nothing until it does - call its close or execute method. See Nothing appears.

Writing the bytes yourself

No library is required: see Code samples for a plain socket in C#, C++, Node.js and Python.

Next pageCode Samples →