Add network printer detection on Windows: support printers from print servers

This commit is contained in:
Quality App Developer
2026-02-06 10:20:57 +02:00
parent 6bcfc3102b
commit fa5c846ebb
4 changed files with 44 additions and 9 deletions

View File

@@ -28,6 +28,7 @@ SYSTEM = platform.system() # 'Linux', 'Windows', 'Darwin'
def get_available_printers():
"""
Get list of available printers (cross-platform).
Includes both local and network printers on Windows.
Returns:
list: List of available printer names, with "PDF" as fallback
@@ -40,14 +41,46 @@ def get_available_printers():
return list(printers.keys()) if printers else ["PDF"]
elif SYSTEM == "Windows":
# Windows: Try win32print first
# Windows: Get both local and network printers
try:
printers = []
for printer_name in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL):
printers.append(printer_name[2])
# Get local printers
try:
for printer_info in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL):
printer_name = printer_info[2]
if printer_name and printer_name not in printers:
printers.append(printer_name)
except:
pass
# Get network printers from print server
try:
for printer_info in win32print.EnumPrinters(win32print.PRINTER_ENUM_NETWORK):
printer_name = printer_info[2]
if printer_name and printer_name not in printers:
printers.append(printer_name)
except:
pass
# Get connected printers (alternative method using WMI)
try:
import wmi
c = wmi.WMI()
for printer in c.Win32_Printer():
printer_name = printer.Name
if printer_name and printer_name not in printers:
printers.append(printer_name)
except:
pass
# Add PDF as fallback option
if "PDF" not in printers:
printers.append("PDF")
return printers if printers else ["PDF"]
except:
# Fallback for Windows if win32print fails
except Exception as e:
print(f"Error getting Windows printers: {e}")
return ["PDF"]
elif SYSTEM == "Darwin":