IDR.Library.PrintAgent.Shared 5.0.0

dotnet add package IDR.Library.PrintAgent.Shared --version 5.0.0
                    
NuGet\Install-Package IDR.Library.PrintAgent.Shared -Version 5.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IDR.Library.PrintAgent.Shared" Version="5.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IDR.Library.PrintAgent.Shared" Version="5.0.0" />
                    
Directory.Packages.props
<PackageReference Include="IDR.Library.PrintAgent.Shared" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IDR.Library.PrintAgent.Shared --version 5.0.0
                    
#r "nuget: IDR.Library.PrintAgent.Shared, 5.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package IDR.Library.PrintAgent.Shared@5.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IDR.Library.PrintAgent.Shared&version=5.0.0
                    
Install as a Cake Addin
#tool nuget:?package=IDR.Library.PrintAgent.Shared&version=5.0.0
                    
Install as a Cake Tool

Depenso Print Agent

Agent d'impression local cross-platform permettant a une application web (WebAssembly) de communiquer avec les imprimantes locales.

Version 2.0.0 - Cross-Platform

L'agent est maintenant disponible pour Windows, macOS et Linux.

Structure du projet

IDR.Library.PrintAgent/
├── IDR.Library.PrintAgent.Shared/           # Bibliotheque partagee cross-platform
│   ├── Abstractions/                        # Interfaces pour les services plateforme
│   ├── Platforms/
│   │   ├── Windows/                         # Implementation Windows Spooler
│   │   └── Unix/                            # Implementation CUPS (macOS/Linux)
│   ├── Protocols/                           # ESC/POS, TSPL, Barcode generation
│   ├── Services/                            # Services principaux
│   └── Models/                              # Modeles de donnees
├── IDR.Library.PrintAgent.Tray/             # Application WPF (Windows uniquement)
├── IDR.Library.PrintAgent.Tray.CrossPlatform/ # Application console cross-platform
└── Installer/                               # Scripts d'installation Windows

Support des plateformes

Fonctionnalite Windows macOS Linux
Imprimantes systeme ✅ Windows Spooler ✅ CUPS ✅ CUPS
Imprimantes USB ✅ ✅ ✅
Imprimantes reseau ✅ ✅ ✅
Imprimantes serie ✅ ✅ ✅
Imprimantes Bluetooth ✅ Via CUPS Via CUPS
ESC/POS ✅ ✅ ✅
TSPL (etiquettes) ✅ ✅ ✅
Interface graphique ✅ (WPF) Console Console

Installation

NuGet (Bibliotheque partagee)

dotnet add package IDR.Library.PrintAgent.Shared

Build depuis les sources

# Compiler le projet Shared
cd IDR.Library.PrintAgent.Shared
dotnet build

# Compiler le Tray cross-platform
cd ../IDR.Library.PrintAgent.Tray.CrossPlatform
dotnet build

Publication pour toutes les plateformes

cd IDR.Library.PrintAgent.Tray.CrossPlatform

# Windows x64
dotnet publish -c Release -r win-x64 -o ./publish/win-x64 --self-contained

# Linux x64
dotnet publish -c Release -r linux-x64 -o ./publish/linux-x64 --self-contained

# macOS Intel
dotnet publish -c Release -r osx-x64 -o ./publish/osx-x64 --self-contained

# macOS Apple Silicon
dotnet publish -c Release -r osx-arm64 -o ./publish/osx-arm64 --self-contained

Utilisation

Demarrer l'agent

# Lancer l'agent (port 5555 par defaut)
./DepensoPrintAgent

# Ou avec un port personnalise
./DepensoPrintAgent --PrintAgent:Port=5556

Sortie console

===========================================
   Depenso Print Agent v2.0.0
   Cross-Platform Edition
===========================================
Plateforme: Windows
Backend: Windows Spooler

Demarrage du serveur sur http://localhost:5555...

Endpoints disponibles:
  - Health:     http://localhost:5555/health
  - Swagger:    http://localhost:5555/swagger
  - API:        http://localhost:5555/api/...

Appuyez sur Ctrl+C pour arreter le serveur.

API REST

L'agent expose une API REST sur http://localhost:5555.

Endpoints principaux

Methode Endpoint Description
GET /health Verification de l'etat du service
GET /api/printers/discover Liste toutes les imprimantes
GET /api/printers/discover/{type} Decouvrir par type
POST /api/printers/test Tester une connexion
POST /api/print Impression d'un job
POST /api/print/text Impression de texte simple
POST /api/print/raw Impression de donnees brutes
POST /api/print/open-drawer Ouverture du tiroir-caisse
POST /api/print/test Page de test
POST /api/label/barcode Impression d'etiquette code-barres
POST /api/label/product Impression d'etiquette produit
POST /api/label/custom Impression d'etiquette personnalisee

Documentation Swagger

Disponible sur http://localhost:5555/swagger quand l'agent est en cours d'execution.

Types de connexion

public enum PrinterConnectionType
{
    USB = 1,
    Network = 2,
    Bluetooth = 3,
    Serial = 4,
    System = 5
}

Exemple d'integration (JavaScript)

// Decouvrir les imprimantes
const response = await fetch('http://localhost:5555/api/printers/discover');
const result = await response.json();
console.log(result.printers);

// Imprimer du texte
await fetch('http://localhost:5555/api/print/text', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    connectionType: 5, // System
    address: "Nom de l'imprimante",
    text: "Hello World!",
    cutAfterPrint: true
  })
});

// Imprimer une etiquette
await fetch('http://localhost:5555/api/label/product', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    connectionType: 5,
    address: "NELKO PM220",
    productName: "Mon Produit",
    barcode: "1234567890123",
    price: "9.99 EUR",
    quantity: 2
  })
});

Exemple d'integration (Blazor WebAssembly)

@inject HttpClient Http

// Verifier que l'agent est disponible
var health = await Http.GetFromJsonAsync<HealthResponse>("http://localhost:5555/health");

// Lister les imprimantes
var result = await Http.GetFromJsonAsync<DiscoveryResult>("http://localhost:5555/api/printers/discover");
var printers = result.Printers;

// Imprimer du texte
await Http.PostAsJsonAsync("http://localhost:5555/api/print/text", new
{
    ConnectionType = 5, // System
    Address = "Mon Imprimante",
    Text = "Bonjour le monde!",
    CutAfterPrint = true
});

Configuration CUPS (macOS/Linux)

Sur macOS et Linux, les imprimantes doivent etre configurees dans CUPS:

# Lister les imprimantes installees
lpstat -p -d

# Ajouter une imprimante USB (mode raw)
sudo lpadmin -p MyPrinter -E -v usb://... -m raw

# Definir comme imprimante par defaut
sudo lpadmin -d MyPrinter

# Tester l'impression
echo "Test" | lp -d MyPrinter

# Verifier les jobs en cours
lpq

Troubleshooting

L'agent ne demarre pas

  • Verifier que le port 5555 n'est pas utilise par une autre application
  • Sur macOS/Linux, verifier que CUPS est installe (which lp)

L'application web ne peut pas se connecter

  • Verifier que l'agent est en cours d'execution
  • Verifier que l'adresse utilisee est bien http://localhost:5555
  • Les navigateurs bloquent les requetes HTTP vers localhost depuis HTTPS

Imprimante non detectee sur macOS/Linux

  • Verifier que l'imprimante est configuree dans CUPS
  • Utiliser lpstat -p pour lister les imprimantes disponibles

Architecture

IDR.Library.PrintAgent.Shared

Shared/
├── Abstractions/
│   ├── IPlatformPrintService.cs        # Interface pour impression plateforme
│   └── IPlatformDiscoveryService.cs    # Interface pour decouverte plateforme
├── Platforms/
│   ├── Windows/
│   │   ├── WindowsPrintService.cs      # Windows Spooler (winspool.drv)
│   │   └── WindowsDiscoveryService.cs  # PrinterSettings
│   └── Unix/
│       ├── CupsPrintService.cs         # CUPS (lp command)
│       └── CupsDiscoveryService.cs     # lpstat/lpinfo
├── Services/
│   ├── IPrintService.cs                # Interface principale impression
│   ├── PrintService.cs                 # Implementation
│   ├── IPrinterDiscoveryService.cs     # Interface principale decouverte
│   └── PrinterDiscoveryService.cs      # Implementation
├── Protocols/
│   ├── EscPosEncoder.cs                # Encodeur ESC/POS
│   ├── TsplEncoder.cs                  # Encodeur TSPL (etiquettes)
│   └── BarcodeImageGenerator.cs        # Generation code-barres (SkiaSharp)
└── Models/
    ├── PrinterInfo.cs                  # Info imprimante
    ├── PrintJob.cs                     # Job d'impression
    └── PrintResult.cs                  # Resultat

Dependances principales

  • SkiaSharp: Generation d'images cross-platform (remplace System.Drawing)
  • ZXing.Net.Bindings.SkiaSharp: Generation de codes-barres cross-platform
  • System.IO.Ports: Communication serie cross-platform
  • System.Drawing.Common: Windows uniquement (pour PrinterSettings)

Licence

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0 183 5/20/2026
4.1.0 216 1/29/2026
4.0.6 148 1/28/2026
4.0.2 184 1/26/2026
4.0.1 145 1/25/2026
4.0.0 140 1/25/2026
1.0.5 145 1/25/2026