shinyorg/shiny/shiny-printing

Claude Code and agent skill by shinyorg/shiny

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Generate code using Shiny.Printers and Shiny.Printing for .NET - thermal / receipt printing (ESC/POS, TSPL) with a fluent PrintDocument over Bluetooth LE, WiFi (raw TCP 9100 + mDNS discovery or subnet sweep, ESC/POS status read-back) and browser Web Bluetooth / Web Serial / WebUSB, plus OS-native printing of PDF, image, HTML and files through AirPrint, Android PrintManager, Windows GDI+/shell, CUPS and window.print, and rendering a receipt to PDF with SkiaSharp

Install

npx vskill@latest install shinyorg/shiny/shiny-printing

SKILL.md

The same SKILL.md was published earlier as shinyorg/shiny/shiny-printing.

Shiny Printing

Two separate printing models. Pick by the printer, not by the platform:

You haveUseWhat it does
A 58/80mm receipt, label or kitchen printer`Shiny.Printers` + a transport packageYou build a PrintDocument; an encoder turns it into ESC/POS (or TSPL) bytes; a transport streams them. The app owns layout.
Any printer the OS knows about (AirPrint, laser, inkjet, CUPS queue)`Shiny.Printing`You hand a PDF / image / HTML / file to the OS print pipeline (dialog, spooler, driver).

They meet in one place: Shiny.Printing.Rendering renders a thermal PrintDocument to a PDF, so the same receipt can go to either.

Packages

PackagePlatformsPurpose
Shiny.Printersany .NETDocument model, PrinterCapabilities, EscPosProtocol, TsplProtocol, PrinterImage, plus the Blazor (WASM / Server) Web Bluetooth, Web Serial and WebUSB transports (AddBrowserPrinting(), namespace Shiny.Printers.Blazor). AOT/trim clean.
Shiny.Printers.BluetoothLEiOS, Mac Catalyst, macOS, Android, Windows, LinuxScan + connect BLE printers via Shiny.BluetoothLE, MTU-chunked writes.
Shiny.Printers.Networkeverywhere incl. Blazor ServerRaw TCP (port 9100) + mDNS discovery via Shiny.Net.Discovery.
Shiny.PrintingiOS, Mac Catalyst, Android, Windows, Linux, macOS, BlazorIPrintService - AirPrint / PrintManager / GDI+ + shell / CUPS, and window.print() on Blazor (AddNativePrinting() picks it on WebAssembly; AddBlazorPrinting() for Blazor Server).
Shiny.Printing.Renderingany .NETIPrintDocumentRenderer - PrintDocument -> PDF with SkiaSharp.

Registration

Every Add* extension lives in namespace Shiny.

csharp
// MauiProgram.cs (iOS, Mac Catalyst, macOS, Android, Windows)
builder.Services.AddBluetoothLePrinting(); // also registers AddBluetoothLE() on these platforms
builder.Services.AddNetworkPrinting(); // also registers AddMdns() unless already registered
builder.Services.AddNativePrinting(); // the platform IPrintService
builder.Services.AddPrintDocumentRendering(); // optional: PrintDocument -> PDF
csharp
// Linux (Shiny.BluetoothLE.Linux) - BLE must be registered FIRST or AddBluetoothLePrinting throws
services.AddBluetoothLE();
services.AddBluetoothLePrinting();
services.AddNetworkPrinting();
services.AddNativePrinting(); // CUPS
csharp
// Blazor
builder.Services.AddBrowserPrinting(); // BrowserPrinterManager (scoped)
builder.Services.AddBlazorPrinting(); // IPrintService over window.print()

Calling AddBluetoothLE<TDelegate>() yourself as well as AddBluetoothLePrinting() is fine - BLE registration is idempotent.

Thermal printing

Build a document
csharp
using Shiny.Printers;
using Shiny.Printers.Document;
PrintDocument BuildReceipt(PrinterCapabilities caps)
{
var doc = new PrintDocument()
.AlignCenter().Bold().Size(2, 2).Line("SHINY MART").ResetStyle()
.AlignLeft().Line(new string('-', caps.CharactersPerLine)) // size layout to the printer
.Line(Columns("Coffee", "$3.50", caps.CharactersPerLine))
.Bold().Line(Columns("TOTAL", "$3.50", caps.CharactersPerLine)).Bold(false)
.AlignCenter()
.Barcode(BarcodeFormat.Code128, "ORDER-100425", height: 70)
.QrCode("https://example.com/r/100425", moduleSize: 6)
.Feed(2);
if (caps.SupportsCut) // feature-detect - cheap 58mm printers have no cutter
doc.Cut();
return doc;
}
static string Columns(string left, string right, int width)
{
var space = width - left.Length - right.Length;
return space < 1 ? $"{left} {right}" : left + new string(' ', space) + right;
}

Rules:

  • Lay out against `printer.Capabilities`, never hard-coded widths. CharactersPerLine is the column count at 1x

(32 on 58mm, 48 on 80mm); DotsPerLine is the max image width (384 / 576).

  • Size(w, h) takes 1-8. ResetStyle() resets alignment, bold, underline and size.
  • WrapText(text, caps.CharactersPerLine) word-wraps long text. Raw(bytes) is the escape hatch for

printer-specific commands (cash drawer kick, code pages).

  • Non-ASCII text: set EscPosProtocol.Encoding and the matching CodePage - the default is ASCII / PC437.
Images

The core never decodes PNG/JPEG. Decode to RGBA yourself (SkiaSharp on MAUI, canvas in the browser) and convert:

csharp
var image = PrinterImage.FromPixels(rgbaSpan, width, height, ImageDithering.FloydSteinberg);
if (image.Width <= printer.Capabilities.DotsPerLine) // wider than the printhead does not print
doc.AlignCenter().Image(image);

ImageDithering.Threshold for logos / line art, FloydSteinberg for photos. RGBA byte order is R, G, B, A; transparency is composited onto white. With SkiaSharp decode as SKColorType.Rgba8888 / SKAlphaType.Unpremul.

Bluetooth LE
csharp
public class ReceiptService(IPrinterScanner scanner, BlePrinterManager manager)
{
public async Task PrintFirstPrinter(PrintDocument doc)
{
// Scan() requests BLE access, filters on KnownPrinterProfiles, and never completes on its own
var found = await scanner.Scan().Take(1).Timeout(TimeSpan.FromSeconds(15)).ToTask();
var printer = await manager.Connect(found);
try
{
await printer.Print(doc);
}
finally
{
(printer as IDisposable)?.Dispose(); // a Printer - disposing disconnects the peripheral
}
}
}
  • DiscoveredPrinter = Peripheral, Name, Rssi, matched Config. The same printer is emitted repeatedly -

de-duplicate on Uuid.

  • Unknown printer? Add a profile to KnownPrinterProfiles.All at startup, or connect with an explicit config:
csharp
var printer = await manager.Connect(peripheralUuid, new BlePrinterConfig
{
ServiceUuid = "0000ff00-0000-1000-8000-00805f9b34fb",
WriteCharacteristicUuid = "0000ff02-0000-1000-8000-00805f9b34fb",
Capabilities = PrinterCapabilities.Paper58mm,
ChunkSize = 100, // null = IPeripheral.Mtu (usable payload, max 512)
InterChunkDelay = TimeSpan.FromMilliseconds(30) // let a small buffer drain
});

Garbled or truncated output on a cheap printer: lower ChunkSize and raise InterChunkDelay.

WiFi / Ethernet
csharp
// fixed install - connect by address
var printer = await networkManager.Connect("192.168.1.50", 9100, PrinterCapabilities.Paper80mm);
// or discover over mDNS (_pdl-datastream._tcp + _printer._tcp, de-duplicated by host:port)
var found = await networkScanner.Scan().Take(1).Timeout(TimeSpan.FromSeconds(10)).ToTask();
var printer = await networkManager.Connect(found);
  • DiscoveredNetworkPrinter.Capabilities defaults to 80mm - mDNS never advertises paper width. Use

found with { Capabilities = PrinterCapabilities.Paper58mm } when you know better.

  • Scan(serviceType) browses a vendor-specific DNS-SD type.
  • Same PrintDocument, same disposal: (printer as IDisposable)?.Dispose() closes the socket.

Printer not found by Scan()? Most cheap receipt printers never advertise mDNS - sweep the subnet for port 9100:

csharp
// completes when done (~1-2s for a /24) - unlike Scan(), which never completes on its own
var printers = await networkScanner.Sweep().ToList();
// custom: explicit subnet / extra ports / 58mm
var printers = await networkScanner.Sweep(new NetworkPrinterSweepConfig
{
Networks = [IPNetwork.Parse("192.168.10.0/24")],
Ports = [9100, 9101],
Capabilities = PrinterCapabilities.Paper58mm
}).ToList();
  • Default Networks = null sweeps each active IPv4 interface's subnet, narrowed to its /24, skipping the device itself.
  • Swept results: Name = IP, ServiceType = "", Method = NetworkPrinterDiscoveryMethod.PortSweep. Merging with

Scan()? de-duplicate on $"{Host}:{Port}".

  • Anything on 9100 answers (laser printers too). A printer busy with another client's connection may be missed.
Printer status (paper out, cover open, cutter, drawer)
csharp
if (printer.SupportsStatus) // ESC/POS over TCP only - BLE and browser transports are write-only
{
var status = await printer.GetStatus(); // TimeoutException if the printer ignores DLE EOT
if (!status.CanPrint)
Show(status.IsPaperOut ? "Load paper" : status.IsCoverOpen ? "Close the cover" : "Printer error");
else if (status.IsPaperNearEnd)
Show("Paper low");
}
  • PrinterStatus: IsOnline, IsCoverOpen, IsPaperOut, IsPaperNearEnd, IsCutterError,

HasUnrecoverableError, HasAutoRecoverableError, IsDrawerSensorHigh (polarity depends on the drawer - never call it "open" without checking), plus CanPrint / HasError.

  • Never call GetStatus() without checking SupportsStatus - it throws NotSupportedException.
  • Timeout: NetworkPrinterConfig.StatusTimeout (default 3s). Non-status reply -> InvalidDataException.
  • Safe to call while printing - the query waits for the in-flight send.
Blazor (browser transports)
razor
@inject BrowserPrinterManager Printers
@implements IAsyncDisposable
<button @onclick="Connect" disabled="@(!support.Serial)">Connect printer</button>
@code {
BrowserPrintingSupport support = new(false, false, false, false);
BrowserPrinter? printer;
protected override async Task OnAfterRenderAsync(bool first)
{
if (first)
{
support = await Printers.GetSupport(); // JS interop only after first render
StateHasChanged();
}
}
async Task Connect() // MUST run from a click - browsers reject device choosers otherwise
{
try
{
printer = await Printers.RequestSerial(new() { BaudRate = 9600, Capabilities = PrinterCapabilities.Paper80mm });
await printer.Print(new PrintDocument().Line("Hello").Feed(3));
}
catch (OperationCanceledException)
{
// user dismissed the chooser
}
}
public ValueTask DisposeAsync() => printer?.DisposeAsync() ?? ValueTask.CompletedTask;
}
  • No scanner on the web. RequestBluetooth() / RequestSerial() / RequestUsb() open the browser chooser and

connect in one call. Never call them from OnInitialized / OnAfterRender.

  • Chromium only (Chrome, Edge, Opera), secure context only (HTTPS or localhost), never iOS. Feature-detect with

GetSupport().

  • Web Bluetooth cannot read the MTU, so WebBluetoothPrinterConfig.ChunkSize defaults to 180.
  • WebUSB fights the OS printer driver - prefer Web Serial where the device has a port.
  • Port-9100 printers are unreachable from WASM (no raw sockets). Under Blazor Server use

Shiny.Printers.Network - the socket runs server-side.

Custom transport or protocol

Implement IPrinterConnection (IsConnected, WhenStatusChanged() replaying the current state, SendAsync(ReadOnlyMemory<byte>) honouring the transport's payload limit) or IPrinterProtocol (Encode(PrintDocument, PrinterCapabilities) => byte[]), then compose: new Printer(connection, protocol, caps). For status, the transport also implements IPrinterQueryConnection (Query(request, responseLength)) and the protocol IPrinterStatusProtocol (QueryStatus(connection)); Printer.SupportsStatus lights up when both do.

OS-native printing

csharp
public class DocumentPrinter(IPrintService print, IPrintDocumentRenderer renderer)
{
public async Task Print(byte[] pdf)
{
var result = await print.Print(PrintJob.Pdf(pdf, new() { JobName = "Invoice 1042" }));
if (!result.IsSuccess)
Console.WriteLine($"{result.Status}: {result.Error}");
}

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
1,583
Repository forks
248
7-day trend score
42

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/shinyorg/shiny/shiny-printing/badge)](https://verified-skill.com/skills/shinyorg/shiny/shiny-printing)

Something wrong with this skill or its page? Tell us.