Printer Event Handler
A cross-platform Rust library for monitoring printer status and events on Windows and Linux systems.
Features
- 🖨️ Cross-platform support - Works on Windows (WMI) and Linux (CUPS)
- 📊 Real-time monitoring - Monitor printer status changes with customizable intervals
- 🔍 Printer discovery - List and find printers on your system
- ⚡ Async/await support - Built on Tokio for efficient asynchronous operations
- 🛡️ Type-safe - Strongly typed printer status and error states
- 📦 Library + CLI - Use as a library in your projects or as a standalone CLI tool
Quick Start
As a Library
Add this to your Cargo.toml:
[]
= "1.1.0"
= { = "1.0", = ["full"] }
Basic Usage
use ;
async
Monitor Printer Status Changes
use PrinterMonitor;
async
Find Specific Printer
use PrinterMonitor;
async
Check for Changes
use PrinterMonitor;
use ;
async
CLI Usage
The crate also provides a command-line interface:
# Install from crates.io
# Or run directly from source
List All Printers
Output:
Printer Status Checker
======================
Found 3 printer(s):
Printer #1: HP LaserJet Pro MFP M428f
Status: Idle
Error State: No Error
Offline: No
Default Printer: Yes
Printer #2: HPDC7777 (HP Smart Tank 580-590 series)
Status: Offline
Error State: Service Requested
Offline: Yes
Printer #3: Microsoft Print to PDF
Status: Idle
Error State: No Error
Offline: No
Monitor a Specific Printer
Output:
Printer Status Monitor Service
==============================
Monitoring printer 'HP LaserJet Pro' every 60 seconds...
Press Ctrl+C to stop
[2024-01-15 14:30:15] Printer 'HP LaserJet Pro' Initial Status:
Status: Idle
Error State: No Error
Offline: No
[2024-01-15 14:31:15] Checking printer 'HP LaserJet Pro'
[2024-01-15 14:32:15] Printer 'HP LaserJet Pro' Status Changed:
Status: Idle -> Printing
Error State: No Error -> No Error
Offline: No
[2024-01-15 14:33:15] Printer 'HP LaserJet Pro' Status Changed:
Status: Printing -> Busy
Error State: No Error -> No Error
Offline: No
Platform Support
| Platform | Backend | Requirements | Coverage |
|---|---|---|---|
| Windows | WMI (Windows Management Instrumentation) | None (built-in) | Complete Win32_Printer support - All 26 PrinterState values (0-25) and 12 DetectedErrorState values (0-11) https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-printer |
| Linux | CUPS (Common Unix Printing System) | cups-client package recommended |
Basic status detection (idle, printing, offline) with CUPS integration |
Linux Setup
On Ubuntu/Debian:
On RHEL/CentOS/Fedora:
API Reference
Core Types
PrinterMonitor- Main entry point for all printer operationsPrinter- Represents a printer and its current statePrinterStatus- Printer status enum (Idle, Printing, Offline, etc.)ErrorState- Error condition enum (NoError, Jammed, NoPaper, etc.)PrinterError- Error type for all operations
Printer Status Values
The library provides comprehensive support for all Win32_Printer states:
Error States
Complete support for Win32_Printer DetectedErrorState values:
Examples
Check out the examples directory for more usage patterns:
basic_listing.rs- List all printersmonitor_changes.rs- Monitor status changeserror_handling.rs- Proper error handlingasync_patterns.rs- Advanced async usage
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development
# Clone the repository
# Run tests
# Check formatting
# Run linter
# Build documentation
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Changelog
See CHANGELOG.md for details about changes in each version.