Getting Started with EricksonLopez.Printing
L3StableNuGet: v1.0.0Local HEAD: v2.0.0AOT: Partial
Install EricksonLopez.Printing and the command-language package for your hardware (EricksonLopez.Printing.EscPos or EricksonLopez.Printing.Zpl, 1.0.0 on NuGet).
dotnet add package EricksonLopez.Printing --version 1.0.0<PackageReference Include="EricksonLopez.Printing" Version="1.0.0" /><PackageVersion Include="EricksonLopez.Printing" Version="1.0.0" />dotnet add package EricksonLopez.Printing.EscPos --version 1.0.0dotnet add package EricksonLopez.Printing.Zpl --version 1.0.0Quick Start: ESC/POS Receipt, ZPL Label & Pooled TCP DI
Section titled “Quick Start: ESC/POS Receipt, ZPL Label & Pooled TCP DI”EscPosBuilder uses RecyclableMemoryStream (using var escPos = new EscPosBuilder();), while AddPooledTcpPrinter registers IPrinterClient as a singleton:
using System;using EricksonLopez.Printing;using EricksonLopez.Printing.EscPos;using EricksonLopez.Printing.Zpl;using Microsoft.Extensions.DependencyInjection;
namespace Example.PrintingQuickStart;
public static class PrintingUsage{ public static void BuildAndRegister() { using var escPos = new EscPosBuilder(); IPrintDocument receipt = escPos .Initialize() .Align(EscPosAlignment.Center) .DoubleSize() .Line("NORTHWIND MARKET") .FontSize(1, 1) .Align(EscPosAlignment.Left) .TableRow("2x Espresso", "$6.50", totalWidth: 42, fillChar: '.') .Cut() .Build();
if (receipt.GetMemory().IsEmpty) { throw new InvalidOperationException("Receipt buffer cannot be empty."); }
IPrintDocument label = new ZplBuilder() .LabelDimensions(800, 1200) .Text(40, 40, "SHIP-2026-001", ZplFont.Font0, 36, 36) .Build();
if (label.GetMemory().IsEmpty) { throw new InvalidOperationException("ZPL label buffer cannot be empty."); }
var services = new ServiceCollection(); services.AddPooledTcpPrinter(options => { options.Host = "192.168.1.200"; options.Port = 9100; options.TimeoutMs = 5000; });
using var provider = services.BuildServiceProvider( new ServiceProviderOptions { ValidateOnBuild = true, ValidateScopes = true });
var client = provider.GetRequiredService<IPrinterClient>(); if (client is null) { throw new InvalidOperationException("IPrinterClient was not resolved."); } }}