Ir al contenido

Buscar en el Ecosistema EricksonLopez.*

Escribe el nombre de una librería, ID de paquete NuGet, tipo .NET o concepto arquitectónico para buscar en el portal.

Primeros Pasos con EricksonLopez.Printing

Instala EricksonLopez.Printing y el paquete de comandos de tu impresora (EricksonLopez.Printing.EscPos o EricksonLopez.Printing.Zpl, 1.0.0 en NuGet).

dotnet add package EricksonLopez.Printing --version 1.0.0
Ventana de terminal
dotnet add package EricksonLopez.Printing.EscPos --version 1.0.0
dotnet add package EricksonLopez.Printing.Zpl --version 1.0.0

EscPosBuilder usa RecyclableMemoryStream (using var escPos = new EscPosBuilder();), mientras AddPooledTcpPrinter registra IPrinterClient como 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.");
}
}
}