# Quality Recticel Print Service - Native Windows A lightweight Windows service that provides local HTTP API for silent PDF printing from the Quality Recticel web application. This is a **native PowerShell implementation** with zero external dependencies. ## 🏗️ Technical Architecture ``` ┌─────────────────────────────────────────────────────────────┐ │ Quality Recticel Web App │ │ (print_module.html) │ └─────────────────────┬───────────────────────────────────────┘ │ HTTP Request ▼ ┌─────────────────────────────────────────────────────────────┐ │ Native PowerShell Print Service │ │ (localhost:8765) │ │ ┌─────────────┐ ┌──────────────┐ ┌─────────────────┐ │ │ │ PowerShell │ │ CORS │ │ PDF Handler │ │ │ │ HTTP Server │ │ Support │ │ & WMI │ │ │ └─────────────┘ └──────────────┘ └─────────────────┘ │ └─────────────────────┬───────────────────────────────────────┘ │ Native Messaging (Optional) ▼ ┌─────────────────────────────────────────────────────────────┐ │ Chrome Extension │ │ ┌─────────────┐ ┌──────────────┐ ┌─────────────────┐ │ │ │ Background │ │ Content │ │ Popup │ │ │ │ Service │ │ Script │ │ UI │ │ │ │ Worker │ │ │ │ │ │ │ └─────────────┘ └──────────────┘ └─────────────────┘ │ └─────────────────────────────────────────────────────────────┘ ``` ## Overview This service creates a local HTTP server on `localhost:8765` that receives print requests from the Quality Recticel web application and handles silent PDF printing to local printers. ## Key Features - **🚀 Native Windows**: Pure PowerShell implementation - no Python or external dependencies - **🖨️ Silent Printing**: Print PDFs without showing print dialogs - **🔧 Printer Management**: List and select available local printers - **⚙️ Windows Service**: Runs automatically in the background - **🌐 Chrome Extension Integration**: Works seamlessly with the Quality Recticel Chrome extension - **📡 REST API**: Simple HTTP endpoints for printing operations - **📝 Comprehensive Logging**: Detailed service logs for troubleshooting ## Quick Installation ### Prerequisites - Windows 10/11 or Windows Server 2016+ - Administrator privileges - PowerShell (included with Windows) - Chrome browser (for the extension) ### Install Steps 1. **Download Service Package** - Download the complete service package from the Quality Recticel system - Extract all files to a temporary folder 2. **Run Native Installer** ```batch # Right-click and "Run as administrator" install_native_service.bat ``` 3. **Install Chrome Extension** - Open Chrome and go to `chrome://extensions/` - Enable "Developer mode" - Click "Load unpacked" and select the `chrome_extension` folder 4. **Test Installation** - Open your browser to: http://localhost:8765/health - You should see a JSON response indicating the service is healthy ## Service Architecture ### Native PowerShell Service - **No Dependencies**: Uses only built-in Windows components - **HTTP Listener**: .NET HttpListener for web requests - **WMI Integration**: Windows Management Instrumentation for printer access - **Service Integration**: Native Windows Service Control Manager ### File Structure ``` C:\Program Files\QualityRecticel\PrintService\ ├── print_service.ps1 # Main PowerShell service script └── print_service.log # Service activity log ``` ## API Endpoints ### Health Check ```http GET http://localhost:8765/health ``` **Response:** ```json { "status": "healthy", "service": "Quality Recticel Print Service", "version": "1.0", "timestamp": "2024-01-15 14:30:25", "platform": "Windows PowerShell" } ``` ### List Printers ```http GET http://localhost:8765/printers ``` **Response:** ```json { "success": true, "printers": [ { "name": "HP LaserJet Pro", "driver": "HP Universal Printing PCL 6", "port": "IP_192.168.1.100", "is_default": true, "status": 3 } ], "count": 1 } ``` ### Print PDF ```http POST http://localhost:8765/print/pdf POST http://localhost:8765/print/silent Content-Type: application/json { "pdf_url": "https://example.com/document.pdf", "printer_name": "HP LaserJet Pro", "copies": 1 } ``` **Response:** ```json { "success": true, "message": "Print job sent successfully", "printer": "HP LaserJet Pro", "timestamp": "2024-01-15 14:30:25" } ``` ## Service Management ### Using Service Control Manager ```batch # Start service sc start QualityRecticelPrintService # Stop service sc stop QualityRecticelPrintService # Check status sc query QualityRecticelPrintService # Restart service sc stop QualityRecticelPrintService && sc start QualityRecticelPrintService ``` ### Using Services GUI 1. Press `Windows + R`, type `services.msc` 2. Find "Quality Recticel Print Service" 3. Right-click for start/stop/restart options ### View Logs Service logs are automatically written to: ``` C:\Program Files\QualityRecticel\PrintService\print_service.log ``` ## Troubleshooting ### Service Won't Start 1. **Check Administrator Rights**: Ensure installer was run as Administrator 2. **PowerShell Execution Policy**: Verify PowerShell execution policy allows scripts ```powershell Get-ExecutionPolicy # Should be RemoteSigned or Unrestricted ``` 3. **Port Conflict**: Check if port 8765 is already in use ```cmd netstat -ano | findstr :8765 ``` 4. **Service Logs**: Check the log file for detailed error messages ### Printing Issues 1. **Printer Access**: Verify printers are accessible from Windows services 2. **PDF Access**: Ensure PDF URLs are accessible from the service context 3. **Print Queue**: Check Windows print queue for stuck jobs 4. **Permissions**: Verify service has permission to access printers ### Chrome Extension Issues 1. **Service Connection**: Test http://localhost:8765/health in browser 2. **Extension Loading**: Verify extension is properly loaded in Chrome 3. **CORS**: Service includes proper CORS headers for browser access 4. **Console Errors**: Check browser console for JavaScript errors ## Security Features - **Localhost Only**: Service only accepts connections from 127.0.0.1/localhost - **No External Access**: No outbound network requirements except for PDF downloads - **Temporary Files**: PDF downloads are cleaned up automatically - **Service Account**: Runs with minimal required privileges - **CORS Protection**: Proper cross-origin resource sharing headers ## Uninstallation ### Automated Uninstall ```batch # Right-click and "Run as administrator" uninstall_service.bat ``` ### Manual Uninstall ```batch # Stop and delete service sc stop QualityRecticelPrintService sc delete QualityRecticelPrintService # Remove files (optional) rmdir /s "C:\Program Files\QualityRecticel" ``` ## Advantages of Native Solution ✅ **Zero Dependencies**: No Python, Flask, or external packages required ✅ **Faster Installation**: No package downloads or environment setup ✅ **Better Integration**: Native Windows service with proper lifecycle management ✅ **Smaller Footprint**: Minimal disk space and memory usage ✅ **Enterprise Ready**: Uses only trusted Windows components ✅ **Easier Deployment**: Single installer with no prerequisites ## Development Notes ### PowerShell Service Implementation The service uses PowerShell's built-in capabilities: - `System.Net.HttpListener` for HTTP server functionality - `Get-WmiObject Win32_Printer` for printer enumeration - `System.Net.WebClient` for PDF downloads - Native Windows service architecture ### Why PowerShell vs Python? - **Deployment**: No need to install Python runtime or pip packages - **Security**: Uses only Microsoft-signed components - **Performance**: Faster startup and lower memory usage - **Maintenance**: Easier to troubleshoot with native Windows tools - **Enterprise**: Better compliance with corporate security policies ## Support For issues or questions: 1. Check the troubleshooting section above 2. Review service logs at `C:\Program Files\QualityRecticel\PrintService\print_service.log` 3. Test individual endpoints using browser or curl 4. Contact Quality Recticel IT support with log details ## File Inventory - `install_native_service.bat` - Service installer (run as Administrator) - `uninstall_service.bat` - Service removal script - `print_service.ps1` - Main PowerShell service implementation - `chrome_extension/` - Chrome extension files (optional) - `README.md` - This documentation file