Bibliotheque partagee cross-platform pour l'impression locale. Inclut les services d'impression, la decouverte d'imprimantes, les encodeurs ESC/POS et TSPL, la generation de codes-barres avec ZXing.Net. Supporte Windows, macOS et Linux.
$ dotnet add package IDR.Library.PrintAgent.SharedAgent d'impression local cross-platform permettant a une application web (WebAssembly) de communiquer avec les imprimantes locales.
L'agent est maintenant disponible pour Windows, macOS et Linux.
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
| 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 |
dotnet add package IDR.Library.PrintAgent.Shared
# Compiler le projet Shared
cd IDR.Library.PrintAgent.Shared
dotnet build
# Compiler le Tray cross-platform
cd ../IDR.Library.PrintAgent.Tray.CrossPlatform
dotnet build
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
# Lancer l'agent (port 5555 par defaut)
./DepensoPrintAgent
# Ou avec un port personnalise
./DepensoPrintAgent --PrintAgent:Port=5556
===========================================
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.
L'agent expose une API REST sur http://localhost:5555.
| 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 |
Disponible sur http://localhost:5555/swagger quand l'agent est en cours d'execution.
public enum PrinterConnectionType
{
USB = 1,
Network = 2,
Bluetooth = 3,
Serial = 4,
System = 5
}
// 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
})
});
@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
});
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
which lp)http://localhost:5555lpstat -p pour lister les imprimantes disponiblesShared/
├── 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
MIT