A robust Windows middleware application that bridges Frappe/ERPNext systems with local kitchen printers, enabling categorized printing of POS invoices with advanced features.
- 🖨️ Multi-Printer Support: Automatically detects and manages multiple local printers
- 📦 Item Group Categorization: Routes different item categories to specific printers
- 🧾 Invoice Generation: Converts HTML templates to PDF for high-quality printing
- 🔌 Real-time Communication: Uses Socket.IO for instant invoice processing
- 🔒 Secure Authentication: Token-based API authentication with session management
- 📊 Order Number Tracking: Maintains sequential order numbers across sessions
- 🖼️ Letterhead Support: Customizable invoice templates with company branding
- 📝 Comprehensive Logging: Detailed logging for troubleshooting
graph TD
A[ERPNext] -->|Socket.IO Events| B[Windows Middleware]
B --> C[Printer Handler]
C --> D[HTML Rendering]
C --> E[PDF Generation]
C --> F[Silent Printing]
D -->|wkhtmltopdf| E
E -->|SumatraPDF| F
F --> G[Kitchen Printer 1]
F --> H[Kitchen Printer 2]
F --> I[Receipt Printer]
- Python 3.9+
- Windows OS (for win32print functionality)
- SumatraPDF (for silent PDF printing)
- wkhtmltopdf (for HTML to PDF conversion)
- Access to Frappe/ERPNext system with local_printers app installed
git clone https://github.com/Ahmed-Mansy-Mansico/local_printers_winapp.git
cd local_printers_winapppip install -r requirements.txt- Install SumatraPDF and add to PATH
- Install wkhtmltopdf and note the installation path
Create a config.json file with the following structure:
{
"FRAPPE_SOCKET_URL": "https://your-erpnext-site.com",
"LOGIN_URL": "https://your-erpnext-site.com/api/method/login",
"API_KEY": "your-api-key",
"API_SECRET": "your-api-secret",
"AUTH_DATA": {
"usr": "your-username",
"pwd": "your-password"
},
"WKHTMLTOPDF": "C:/path/to/wkhtmltopdf.exe",
"SUMATRA_PDF_PATH": "C:/Program Files/SumatraPDF/SumatraPDF.exe",
"LETTERHEAD_IMAGE": "https://your-site.com/path/to/letterhead.png",
"main_printer": "ReceiptPrinter",
"item_groups": {
"Beverages": "BarPrinter",
"Desserts": "KitchenPrinter2"
},
"daily_order_start": 1
}- Invoice Submission: POS invoice submitted in ERPNext
- Event Trigger: Socket.IO event sent to Windows middleware
- Template Rendering: HTML template generated with invoice data
- PDF Conversion: HTML converted to PDF using wkhtmltopdf
- Silent Printing: PDF sent to appropriate printer via SumatraPDF
- Order Tracking: Sequential order number maintained
The printer_handlers.py module provides these key functions:
- Enumerates all locally available printers
- Returns a list of printer names
- Uses SumatraPDF for silent printing
- Supports custom print settings
- Includes comprehensive error handling
- Renders HTML templates with invoice data
- Generates PDFs with wkhtmltopdf
- Handles letterhead images and custom formatting
- Manages temporary PDF files
- Retrieves current order number from ERPNext
- Uses API authentication tokens
- Implements error handling for network issues
| Issue | Solution |
|---|---|
| Connection failures | Verify config.json settings and network connectivity |
| Printing errors | Check printer availability and SumatraPDF installation |
| PDF generation failures | Confirm wkhtmltopdf path and permissions |
| Authentication problems | Validate API keys and user credentials |
The application provides detailed logs in the console with timestamps and log levels:
2023-11-15 14:30:45,123 - INFO - Processing invoice: INV-2023-001
2023-11-15 14:30:46,456 - INFO - Generated PDF at: C:\Temp\tmp1234.pdf
2023-11-15 14:30:47,789 - INFO - Sent to printer BarPrinter successfully
- local_printers: Frappe app for ERPNext integration
- validate_local_printers: Validation service for authorized usage
MIT License - See LICENSE for details.
This enhanced README includes:
- More detailed feature breakdown
- Visual system architecture diagram
- Step-by-step installation instructions
- Comprehensive configuration details
- Detailed printing process workflow
- Printer handler function documentation
- Troubleshooting table
- Logging information
- Related project links
The document provides everything needed to understand, install, configure, and troubleshoot the application.