6amtech/laravel-electron-printing
Composer 安装命令:
composer require 6amtech/laravel-electron-printing
包简介
Silent background printing service for Laravel using Electron. Print HTML, Blade views, URLs, and PDFs to any printer without user interaction. Perfect for POS, restaurants, and e-commerce.
关键字:
README 文档
README
🖨️ Silent background printing for Laravel - Print HTML, Blade views, URLs, and PDFs directly to any printer without user interaction.
Perfect for POS systems, restaurants, warehouses, e-commerce, and any application requiring automated printing.
⚡ Quick Start
# 1. Install package composer require 6amtech/laravel-electron-printing # 2. Run install command php artisan electron-printing:install # 3. Configure .env PRINT_SERVICE_ENABLED=true PRINT_SERVICE_URL=http://localhost:3000 PRINT_USE_WEBSOCKET=false PRINT_BROADCAST_CHANNEL=printing # 4. Start Electron service cd electron-print-service npm install npm start
Print in your Laravel app:
use LaravelElectronPrinting\Facades\ElectronPrint; ElectronPrint::printView('receipt', ['order' => $order], null, 'thermal_80mm');
📦 Installation
Step 1: Install Package
composer require 6amtech/laravel-electron-printing
Step 2: Run Install Command
php artisan electron-printing:install
This command will:
- Publish the config file to
config/electron-printing.php - Publish the Electron app to
electron-print-service/ - Show you the required
.envconfiguration
Step 3: Configure Environment
Add these to your .env file:
PRINT_SERVICE_ENABLED=true PRINT_SERVICE_URL=http://localhost:3000 PRINT_USE_WEBSOCKET=false PRINT_BROADCAST_CHANNEL=printing PRINT_MAX_PAYLOAD_SIZE=50
Step 4: Install Printer Drivers
⚠️ Important: You must install the genuine printer drivers on the machine running the Electron service.
- Thermal Printers: Install manufacturer drivers (EPSON, Star, etc.)
- Standard Printers: Install from manufacturer website
- Network Printers: Configure network connection first
Step 5: Start the Electron Service
Option A: Run from Source (Development)
cd electron-print-service
npm install
npm start
The service will:
- Start on
http://localhost:3000 - Run in the background with a system tray icon
- Auto-start on system boot (optional)
Option B: Build Standalone App (Production)
If you want to distribute a ready-to-use application without requiring Node.js:
Build for your platform:
cd electron-print-service # For macOS npm run build:mac # For Windows npm run build:win # For Linux npm run build:linux # For all platforms (requires macOS) npm run build:all
Built apps will be in: electron-print-service/dist/
Installation:
-
macOS:
- Open
6amTech Printing Service-1.0.0-mac.dmg - Drag app to Applications folder
- Open from Applications (right-click → Open first time)
- Open
-
Windows:
- Run
6amTech Printing Service Setup 1.0.0.exe - Follow installer wizard
- App will auto-start on system boot
- Run
-
Linux:
- Install
.deb:sudo dpkg -i 6amTech-Printing-Service-1.0.0.deb - Or run
.AppImagedirectly (no installation needed)
- Install
Note: Built apps don't require Node.js or npm to be installed on the target machine.
Remote/Network Setup (Different Machine)
On the machine with printers connected:
- Edit config (
electron-print-service/config.json):
{
"listenIP": "0.0.0.0",
"port": 3000
}
- Start the service:
cd electron-print-service
npm install
npm start
- Note the machine's IP address:
# Windows ipconfig # macOS/Linux ifconfig # or ip addr show
On your Laravel server:
Update .env with the remote machine's IP:
PRINT_SERVICE_URL=http://192.168.1.100:3000
Firewall Configuration:
- Allow incoming connections on port 3000
- Windows:
Windows Defender Firewall → Allow an app - macOS:
System Preferences → Security & Privacy → Firewall - Linux:
sudo ufw allow 3000
🚀 Usage
Basic Printing
use LaravelElectronPrinting\Facades\ElectronPrint; // Print HTML ElectronPrint::printHtml('<h1>Hello World</h1>'); // Print Blade view ElectronPrint::printView('receipt', ['order' => $order]); // Print to specific printer ElectronPrint::printView('receipt', $data, 'EPSON TM-T88V');
Using Print Profiles
Pre-configured profiles in config/electron-printing.php:
// Thermal 80mm receipt ElectronPrint::printView('receipt', $data, null, 'thermal_80mm'); // Thermal 58mm receipt ElectronPrint::printView('receipt', $data, null, 'thermal_58mm'); // A4 document ElectronPrint::printView('invoice', $data, null, 'a4'); // A4 landscape ElectronPrint::printView('report', $data, null, 'a4_landscape'); // Label printer ElectronPrint::printView('label', $data, null, 'label');
Custom Print Options
ElectronPrint::printView('receipt', $data, null, [ 'pageSize' => ['width' => 80000, 'height' => 297000], 'marginsType' => 1, 'printBackground' => true, 'scaleFactor' => 100 ]);
PDF Printing
// From file ElectronPrint::printPdfFile(storage_path('app/invoice.pdf')); // From URL ElectronPrint::printPdfUrl('https://example.com/invoice.pdf'); // From Base64 ElectronPrint::printPdfBase64($base64String); // With profile ElectronPrint::printPdfFile(storage_path('app/invoice.pdf'), null, 'a4');
Print from URL
ElectronPrint::printUrl('https://example.com/receipt');
Get Available Printers
$printers = ElectronPrint::getPrinters(); // Returns: ['EPSON TM-T88V', 'HP LaserJet', ...]
Check Service Health
if (ElectronPrint::isHealthy()) { // Service is running }
⚙️ Configuration
Environment Variables
# Enable/disable printing PRINT_SERVICE_ENABLED=true # Electron service URL (local or remote) PRINT_SERVICE_URL=http://localhost:3000 # Request timeout (seconds) PRINT_SERVICE_TIMEOUT=30 # Max payload size for large PDFs (MB) PRINT_MAX_PAYLOAD_SIZE=50 # Default printer (leave empty for system default) PRINT_DEFAULT_PRINTER= # WebSocket mode (optional) PRINT_USE_WEBSOCKET=false PRINT_BROADCAST_CHANNEL=printing # Logging PRINT_LOGGING_ENABLED=true PRINT_LOG_CHANNEL=daily
Custom Print Profiles
Edit config/electron-printing.php:
'profiles' => [ 'my_custom_printer' => [ 'pageSize' => ['width' => 80000, 'height' => 297000], 'marginsType' => 1, 'printBackground' => true, 'scaleFactor' => 100, ], ],
Use it:
ElectronPrint::printView('receipt', $data, null, 'my_custom_printer');
Electron Service Configuration
Edit electron-print-service/config.json:
{
"port": 3000,
"listenIP": "0.0.0.0",
"maxPayloadSize": 50,
"websocket": {
"enabled": false,
"host": "https://your-domain.com",
"auth": {}
}
}
🌐 Network Printing Setup
Scenario 1: Laravel + Electron on Same Machine
PRINT_SERVICE_URL=http://localhost:3000
Scenario 2: Laravel on Server, Electron on Workstation
Workstation (with printers):
- IP:
192.168.1.100 - Edit
electron-print-service/config.json:{ "listenIP": "0.0.0.0", "port": 3000 } - Start service:
npm start
Laravel Server:
PRINT_SERVICE_URL=http://192.168.1.100:3000
Scenario 3: Multiple Workstations
Each workstation runs its own Electron service:
Workstation 1 (Kitchen):
{ "listenIP": "0.0.0.0", "port": 3000 }
Workstation 2 (Counter):
{ "listenIP": "0.0.0.0", "port": 3001 }
Laravel:
// Kitchen printer ElectronPrint::printView('kitchen-order', $data, 'Kitchen Printer', 'thermal_80mm'); // Counter printer (different service) $counterService = new ElectronPrintService('http://192.168.1.101:3001'); $counterService->printView('receipt', $data, 'Receipt Printer', 'thermal_80mm');
📚 API Reference
use LaravelElectronPrinting\Facades\ElectronPrint; // Print methods ElectronPrint::printHtml($html, $printer, $options) ElectronPrint::printView($view, $data, $printer, $options) ElectronPrint::printUrl($url, $printer, $options) ElectronPrint::printPdfFile($path, $printer, $options) ElectronPrint::printPdfUrl($url, $printer, $options) ElectronPrint::printPdfBase64($base64, $printer, $options) // Utility ElectronPrint::getPrinters() // Returns array of printer names ElectronPrint::isHealthy() // Returns true if service running // All methods return: ['success' => bool, 'message' => string]
🧪 Testing
# Test the installation php artisan electron-printing:test # Run package tests composer test
🐛 Troubleshooting
Service Not Connecting
Error: Print service error: Connection refused
Solutions:
- Check if Electron service is running:
curl http://localhost:3000/health
- Verify
PRINT_SERVICE_URLin.env - Check firewall settings
- For network printing, ensure
listenIPis0.0.0.0
Printer Not Found
Error: Printer name not recognized
Solutions:
- Get available printers:
dd(ElectronPrint::getPrinters());
- Use exact printer name from the list
- Install printer drivers on the machine running Electron service
- Use
nullfor system default printer
Payload Too Large
Error: 413 Payload Too Large
Solution:
PRINT_MAX_PAYLOAD_SIZE=100 # Increase to 100MB
Restart both Laravel and Electron service.
Print Quality Issues
Solutions:
- Use correct profile for your printer type
- Adjust
scaleFactor(default: 100) - Enable
printBackground: truefor colored content - Check printer driver settings
Port Already in Use
Error: Port 3000 is already in use
Solution - Find and kill the process:
macOS/Linux:
# Find process using port 3000 lsof -ti:3000 # Kill the process kill -9 $(lsof -ti:3000) # Or change port in electron-print-service/config.json
Windows:
# Find process using port 3000 netstat -ano | findstr :3000 # Kill process (replace PID with actual process ID) taskkill /PID <PID> /F # Or change port in electron-print-service/config.json
Change Port:
Edit electron-print-service/config.json:
{
"port": 3001,
"listenIP": "0.0.0.0"
}
Then update Laravel .env:
PRINT_SERVICE_URL=http://localhost:3001
Network Printing Not Working
Solutions:
- Verify IP address:
ping 192.168.1.100 - Check firewall allows port 3000
- Ensure
listenIP: "0.0.0.0"in Electron config - Test locally first:
http://localhost:3000/health
Electron App Won't Open
macOS
Problem: "App can't be opened because it is from an unidentified developer"
Solution:
# Remove quarantine attribute xattr -cr "/Applications/6amTech Printing Service.app" # Or right-click → Open (first time only)
Problem: App crashes on startup
Solution:
- Check Console.app for error logs
- Ensure printer drivers are installed
- Try running from source:
cd electron-print-service && npm start
Windows
Problem: "Windows protected your PC" warning
Solution:
- Click "More info"
- Click "Run anyway"
- Or: Right-click installer → Properties → Unblock → Apply
Problem: App won't start after installation
Solution:
- Check if port 3000 is already in use:
netstat -ano | findstr :3000
- Run as Administrator
- Check Windows Defender logs
- Reinstall with antivirus temporarily disabled
Linux
Problem: AppImage won't run
Solution:
# Make executable chmod +x 6amTech-Printing-Service-1.0.0.AppImage # Run ./6amTech-Printing-Service-1.0.0.AppImage
Problem: .deb installation fails
Solution:
# Install dependencies sudo apt-get install -f # Try reinstall sudo dpkg -i 6amTech-Printing-Service-1.0.0.deb
Problem: App runs but no system tray icon
Solution:
# Install system tray support sudo apt-get install libappindicator3-1 # For GNOME sudo apt-get install gnome-shell-extension-appindicator
🎯 Features
✅ Silent Printing - No print dialogs
✅ Multiple Formats - HTML, Blade, URL, PDF
✅ Print Profiles - Pre-configured settings
✅ Network Support - Print from any device
✅ Thermal Printers - 80mm, 58mm receipts
✅ Standard Printers - A4, Letter, Labels
✅ Cross-Platform - Windows, macOS, Linux
✅ Large Files - Configurable payload size
📖 Resources
- Complete Documentation - Advanced features and guides
- GitHub Repository - Source code
- Packagist - Package releases
📝 License
MIT License - see LICENSE.md
👨💻 Credits
Developed by: Mainul Islam
Organization: 6amTech
GitHub: @mainulBUBT
Email: mainulislam3057@gmail.com
⭐ Support
If this package helps your project, give it a ⭐ on GitHub!
Made with ❤️ for the Laravel community
6amtech/laravel-electron-printing 适用场景与选型建议
6amtech/laravel-electron-printing 是一款 基于 HTML 开发的 Composer 扩展包,目前已累计 32 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「pos」 「printing」 「receipt」 「printer」 「electron」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 6amtech/laravel-electron-printing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 6amtech/laravel-electron-printing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 6amtech/laravel-electron-printing 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Onslip 360 PHP SDK
CUPS Implementation of IPP - PHP Client API (PHP >= 8.3)
A Guzzle HTTP Client extension for Lightspeed Retail.
Redsys Virtual POS is an unofficial standalone PHP library to handle payments through the spanish payment service Redsys.
Connect any printer to your application with PrintNode Client and easy to use JSON API
Object interface for working with JasperStarter
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-19