Blog

ESC/POS in PHP, Java, C# and Flutter: Libraries and Working Examples

1 November 2026 · 5 min read · By the Raw Print team

Every major language has a mature ESC/POS library, so you rarely need to write printer bytes by hand. Use escpos-php for PHP, escpos-coffee for Java, ESC-POS-.NET for C#, and esc_pos_utils_plus with a Bluetooth plugin for Flutter. Below you'll find install commands and a working receipt for each, with text styles, a QR code, a paper cut and the cash drawer. Every method name was checked against the library's current source code in October 2026.

Library per language:

  • PHP: mike42/escpos-php (PHP 8.2+)
  • Java: anastaciocintra/escpos-coffee (MIT)
  • C#/.NET: ESCPOS_NET (MIT)
  • Flutter: esc_pos_utils_plus to build bytes + print_bluetooth_thermal to send them
  • Python and JavaScript: see ESC/POS explained and ESC/POS in JavaScript

PHP: escpos-php

The most popular ESC/POS library in any language by GitHub stars. The current release requires PHP 8.2 or newer.

composer require mike42/escpos-php
<?php
require __DIR__ . '/vendor/autoload.php';

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

$connector = new NetworkPrintConnector("192.168.1.50", 9100);
$printer = new Printer($connector);

$printer->setJustification(Printer::JUSTIFY_CENTER);
$printer->setTextSize(2, 2);
$printer->text("CORNER CAFE\n");
$printer->setTextSize(1, 1);
$printer->setJustification(Printer::JUSTIFY_LEFT);
$printer->text("1 x Flat white              3.50\n");
$printer->setEmphasis(true);
$printer->text("TOTAL                       3.50\n");
$printer->setEmphasis(false);
$printer->setJustification(Printer::JUSTIFY_CENTER);
$printer->qrCode("https://example.com/r/1042", Printer::QR_ECLEVEL_M, 6);
$printer->feed(2);
$printer->cut();
$printer->pulse();          // open cash drawer (pin 2)
$printer->close();

Connectors: NetworkPrintConnector for IP printers, WindowsPrintConnector for a shared Windows printer (smb:// or the local share name), and FilePrintConnector for a device file such as /dev/usb/lp0 or php://stdout when testing.

Images: $img = EscposImage::load("logo.png"); $printer->graphics($img); Use bitImage() on printers that don't support the graphics command.

Web apps: PHP runs on your server, so it can only reach printers on the server's network. For receipts printed at a customer's counter, generate the bytes in PHP and hand them to the browser, which passes them to a local print app. On Android: rawbt:base64, + the base64 bytes.

Java: escpos-coffee

A tidy, well-documented Java library with styles, barcodes, QR codes, images and dithering.

<dependency>
  <groupId>com.github.anastaciocintra</groupId>
  <artifactId>escpos-coffee</artifactId>
  <version>4.1.0</version>
</dependency>
import com.github.anastaciocintra.escpos.EscPos;
import com.github.anastaciocintra.escpos.EscPosConst;
import com.github.anastaciocintra.escpos.Style;
import com.github.anastaciocintra.escpos.barcode.QRCode;
import com.github.anastaciocintra.output.TcpIpOutputStream;

try (TcpIpOutputStream out = new TcpIpOutputStream("192.168.1.50", 9100)) {
    EscPos escpos = new EscPos(out);

    Style title = new Style()
        .setFontSize(Style.FontSize._2, Style.FontSize._2)
        .setJustification(EscPosConst.Justification.Center);

    escpos.writeLF(title, "CORNER CAFE");
    escpos.writeLF("1 x Flat white              3.50");
    escpos.writeLF(new Style().setBold(true), "TOTAL                       3.50");

    QRCode qr = new QRCode();
    qr.setSize(6).setJustification(EscPosConst.Justification.Center);
    escpos.write(qr, "https://example.com/r/1042");

    escpos.feed(4).cut(EscPos.CutMode.PART);
    escpos.pulsePin(EscPos.PinConnector.Pin_2, 50, 75);   // cash drawer
    escpos.close();
}

Other outputs: PrinterOutputStream prints to an installed system printer by name (use a raw/generic driver). The project's samples repository adds USB and serial streams.

Images: wrap a BufferedImage in EscPosImage with a BitonalThreshold (logos) or BitonalOrderedDither (photos), then write it with a raster image wrapper.

C# / .NET: ESC-POS-.NET

A modern .NET library that runs on Windows, Linux and macOS, with network, serial and file printers and helpers for status monitoring.

dotnet add package ESCPOS_NET
using ESCPOS_NET;
using ESCPOS_NET.Emitters;
using ESCPOS_NET.Utilities;

var printer = new ImmediateNetworkPrinter(new ImmediateNetworkPrinterSettings
{
    ConnectionString = "192.168.1.50:9100",
    PrinterName = "Counter"
});
var e = new EPSON();

await printer.WriteAsync(ByteSplicer.Combine(
    e.CenterAlign(),
    e.SetStyles(PrintStyle.DoubleWidth | PrintStyle.DoubleHeight),
    e.PrintLine("CORNER CAFE"),
    e.SetStyles(PrintStyle.None),
    e.LeftAlign(),
    e.PrintLine("1 x Flat white              3.50"),
    e.SetStyles(PrintStyle.Bold),
    e.PrintLine("TOTAL                       3.50"),
    e.SetStyles(PrintStyle.None),
    e.CenterAlign(),
    e.PrintQRCode("https://example.com/r/1042"),
    e.FullCutAfterFeed(4),
    e.CashDrawerOpenPin2()
));

Other printers: SerialPrinter(portName: "COM5", baudRate: 115200) for serial and Bluetooth virtual COM ports, and file printers for USB device paths.

Images: e.PrintImage(File.ReadAllBytes("logo.png"), true).

Flutter: esc_pos_utils_plus + print_bluetooth_thermal

In Flutter, building bytes and sending them are separate packages. esc_pos_utils_plus generates ESC/POS with a printer capability profile; print_bluetooth_thermal sends bytes to paired Bluetooth printers on Android, iOS, macOS and Windows (recently updated, September 2026).

flutter pub add esc_pos_utils_plus print_bluetooth_thermal
import 'package:esc_pos_utils_plus/esc_pos_utils_plus.dart';
import 'package:print_bluetooth_thermal/print_bluetooth_thermal.dart';

Future<List<int>> buildReceipt() async {
  final profile = await CapabilityProfile.load();
  final g = Generator(PaperSize.mm58, profile);
  var bytes = <int>[];
  bytes += g.reset();
  bytes += g.text('CORNER CAFE',
      styles: const PosStyles(align: PosAlign.center, height: PosTextSize.size2, width: PosTextSize.size2));
  bytes += g.text('1 x Flat white              3.50');
  bytes += g.text('TOTAL                       3.50', styles: const PosStyles(bold: true));
  bytes += g.qrcode('https://example.com/r/1042');
  bytes += g.feed(2);
  bytes += g.cut();
  return bytes;
}

Future<void> printReceipt() async {
  final paired = await PrintBluetoothThermal.pairedBluetooths;
  final mac = paired.first.macAdress;           // let the user choose in real code
  await PrintBluetoothThermal.connect(macPrinterAddress: mac);
  await PrintBluetoothThermal.writeBytes(await buildReceipt());
}

The original esc_pos_utils package hasn't had a release since 2021; the _plus fork is the one to use. On iOS, only BLE or MFi printers can be reached.

The Android shortcut for Flutter

If your Flutter app runs only on Android and your users already have a print app, you can skip Bluetooth entirely: base64-encode the bytes and launch rawbt:base64,… with the url_launcher package. The print app handles pairing, reconnection and slow printers. Raw Print and RawBT both accept these links. The same idea for hybrid apps is explained in thermal printing from Ionic and Cordova.

Things that trip people up in every language

  • Character encoding. Libraries encode text in the printer's code page. Pick the right one, or print other scripts as images.
  • Paper width. Choose 58 mm (32 columns) or 80 mm (42–48 columns) in the library's settings or profile.
  • Cutting. Feed before cutting, or the last line gets sliced. See cut paper and open the cash drawer.
  • QR codes on cheap printers. If the native QR command does nothing, print the code as an image. See images and QR codes.
  • Testing. Use an ESC/POS emulator before you buy paper by the box.

For a side-by-side of libraries, including Python, Android and Go options, read the best ESC/POS libraries on GitHub.

Frequently asked questions

Which PHP library prints to ESC/POS printers?

mike42/escpos-php. Install it with composer require mike42/escpos-php; it supports network, Windows-shared and file/device printers.

How do I print to a thermal printer from C#?

Use the ESCPOS_NET NuGet package: create a network or serial printer, build commands with the EPSON emitter and send them with ByteSplicer.Combine.

What is the best Flutter package for thermal printers?

Combine esc_pos_utils_plus (to generate bytes) with a transport such as print_bluetooth_thermal. The older esc_pos_utils package is no longer updated.

Can a PHP website print directly to the customer's receipt printer?

No, PHP runs on the server. Generate the receipt in PHP, then send it to the device that has the printer: on Android, through a print app and a rawbt: link.