Skip to content
Daniel Meza edited this page Jul 7, 2026 · 3 revisions

CrossEscPos

A cross-platform ESC/POS receipt-printer emulator and a set of layered, independently-usable .NET libraries. It emulates a networked/serial/USB receipt printer so you can test the ESC/POS your POS software emits — rendering the resulting receipts, answering status queries, and simulating paper / cover / drawer / error states.

It ships as four things:

  • a cross-platform desktop app (Avalonia + .NET 10 — Windows, macOS, Linux),
  • a browser app (Avalonia WASM) that runs the emulator in the browser,
  • a headless core you can embed (ESC/POS bytes → PNG, no UI), and
  • NuGet packages for each layer, so you take only what you need.

Start here

  • Getting Started — render your first ticket headless, in ~15 lines.
  • Packages — what each library gives you and how they fit together.
  • Core Emulator — feeding ESC/POS, receipts, printer state, status replies, events.
  • Rendering & Backends — the Skia and managed ImageSharp backends, exporting PNGs.
  • Adding a Render Backend — step-by-step, using the ImageSharp backend as the worked sample.
  • Transports — feed the emulator over TCP / serial / USB.
  • Controls — the reusable Avalonia ReceiptView / PrinterStatePanel.
  • Browser App — render ESC/POS in the browser; switch engines at runtime.

The mental model

flowchart TD
    bytes["ESC/POS bytes"] --> printer["ReceiptPrinter<br/>(Core · headless · no graphics dep)"]
    printer --> stack["ReceiptStack<br/>one Receipt per cut"]
    stack -->|"Render()"| image["IReceiptImage"]
    image --> encoder["IImageEncoder"]
    encoder --> png["PNG bytes<br/>(or an Avalonia Bitmap / browser &lt;img&gt;)"]

    backend["render backend<br/>Rendering.Skia · Rendering.ImageSharp · your own"]
    backend -. "IReceiptImageFactory + ITypefaceProvider" .-> printer
Loading

Core knows nothing about SkiaSharp or Avalonia. You — the host — pick a render backend and inject it. That is the whole design: the emulation is portable (headless, server, WASM) and the rendering is swappable.

Install

dotnet add package CrossEscPos.Core
dotnet add package CrossEscPos.Rendering.Skia        # native SkiaSharp (desktop default)
# …or the managed, WASM-safe backend:
dotnet add package CrossEscPos.Rendering.ImageSharp

Run the apps

dotnet run --project src/CrossEscPos.App.Desktop        # native desktop emulator
dotnet run --project samples/CrossEscPos.Host             # browser app + SignalR host (one origin)
dotnet run --project samples/CrossEscPos.Headless -- ticket.escpos out.png   # ESC/POS → PNG

This project began as a cross-platform port of roydejong/EscPosEmulator (a Windows/WPF app), migrated to Avalonia + .NET 10 and extended with barcode/QR rendering, transports, and a swappable render layer.

Clone this wiki locally