Files
label_printer/build_windows.ps1
scheianuionut f09c365384 Fix printer detection, implement portable deployment with SumatraPDF
- Fixed network printer enumeration (PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS)
- Added printer name truncation to 20 chars with full name mapping
- Implemented silent PDF printing using SumatraPDF with landscape orientation
- Added auto-dismiss for success popup (3 seconds)
- Bundled SumatraPDF inside executable for portable single-file deployment
- Updated build script to embed SumatraPDF
- Added setup_sumatra.ps1 for downloading SumatraPDF portable
- Added DEPLOYMENT.md documentation
2026-02-06 14:00:17 +02:00

131 lines
4.6 KiB
PowerShell

# Label Printer - Windows Build Script (Single File EXE)
# This script builds a standalone LabelPrinter.exe on Windows
# Requirements: Python 3.10-3.13 installed and in PATH
# Note: Python 3.14+ may have compatibility issues
Write-Host ""
Write-Host "========================================================"
Write-Host " Label Printer - Windows Build Script"
Write-Host " Creates: LabelPrinter.exe (Single File)"
Write-Host "========================================================"
Write-Host ""
# Check if Python is installed
try {
$pythonVersion = python --version 2>&1
if ($LASTEXITCODE -ne 0) {
throw "Python not found"
}
} catch {
Write-Host "ERROR: Python is not installed or not in PATH" -ForegroundColor Red
Write-Host "Please install Python 3.10-3.13 from https://www.python.org/"
Write-Host "Make sure to check 'Add Python to PATH' during installation"
Read-Host "Press Enter to exit"
exit 1
}
Write-Host "[1/5] Checking Python installation..." -ForegroundColor Cyan
Write-Host $pythonVersion
Write-Host ""
Write-Host "[2/5] Upgrading pip, setuptools, and wheel..." -ForegroundColor Cyan
python -m pip install --upgrade pip setuptools wheel
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to upgrade pip" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
Write-Host ""
Write-Host "[3/5] Installing dependencies..." -ForegroundColor Cyan
Write-Host "Installing: python-barcode, pillow, reportlab, kivy, pyinstaller, pywin32, wmi..."
pip install python-barcode pillow reportlab kivy pyinstaller pywin32 wmi
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to install dependencies" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
Write-Host ""
Write-Host "[4/6] Checking for SumatraPDF..." -ForegroundColor Cyan
$sumatraPath = "SumatraPDF\SumatraPDF.exe"
if (-not (Test-Path $sumatraPath)) {
Write-Host ""
Write-Host "WARNING: SumatraPDF not found!" -ForegroundColor Yellow
Write-Host "SumatraPDF is required for silent PDF printing." -ForegroundColor Yellow
Write-Host ""
Write-Host "Run the setup script first:" -ForegroundColor Yellow
Write-Host " powershell -ExecutionPolicy Bypass -File setup_sumatra.ps1" -ForegroundColor Cyan
Write-Host ""
$response = Read-Host "Continue building without SumatraPDF? (y/n)"
if ($response -ne "y") {
Write-Host "Build cancelled."
Read-Host "Press Enter to exit"
exit 1
}
Write-Host ""
Write-Host "Building without SumatraPDF (PDF printing will not work)..." -ForegroundColor Yellow
$addBinaryArg = @()
} else {
Write-Host "Found: $sumatraPath" -ForegroundColor Green
# Add SumatraPDF as bundled binary (will be embedded inside the exe)
$addBinaryArg = @("--add-binary", "$sumatraPath;.")
}
Write-Host ""
Write-Host "[5/6] Cleaning old build artifacts..." -ForegroundColor Cyan
if (Test-Path "dist") { Remove-Item -Recurse -Force "dist" }
if (Test-Path "build") { Remove-Item -Recurse -Force "build" }
Remove-Item -Force "*.spec" -ErrorAction SilentlyContinue
Write-Host ""
Write-Host "[6/6] Building executable with PyInstaller..." -ForegroundColor Cyan
Write-Host "This may take 5-15 minutes, please wait..."
Write-Host ""
$pyinstallerArgs = @(
"label_printer_gui.py",
"--onefile",
"--windowed",
"--name=LabelPrinter",
"--distpath=./dist",
"--workpath=./build",
"--hidden-import=kivy",
"--hidden-import=PIL",
"--hidden-import=barcode",
"--hidden-import=reportlab",
"--hidden-import=print_label",
"--hidden-import=print_label_pdf",
"-y"
)
# Add SumatraPDF binary if available (bundles inside the exe)
if ($addBinaryArg) {
$pyinstallerArgs += $addBinaryArg
}
pyinstaller @pyinstallerArgs
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "ERROR: Build failed!" -ForegroundColor Red
Write-Host "Please check the error messages above." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
Write-Host ""
Write-Host "========================================================"
Write-Host " BUILD SUCCESSFUL!" -ForegroundColor Green
Write-Host "========================================================"
Write-Host ""
Write-Host "Executable Location: dist\LabelPrinter.exe" -ForegroundColor Green
Write-Host ""
Write-Host "Next steps:"
Write-Host " 1. Navigate to the dist folder"
Write-Host " 2. Double-click LabelPrinter.exe to run"
Write-Host " 3. You can copy LabelPrinter.exe to other machines"
Write-Host ""
Write-Host "Note: First run may take a moment as Kivy initializes"
Write-Host ""
Read-Host "Press Enter to exit"