# 返回获取所有打印机名称信息 import win32print print_names = [] printers = win32print.EnumPrinters(2) for printer in printers: print_names.append(printer[2]) def get_printer_status(device_name=None): # 获取打印机状态 device_name打印机名称 try: handle = win32print.OpenPrinter(device_name) except: return '未获取' properties = win32print.GetPrinter(handle, 2) attributes = properties['Attributes'] status = '脱机' if (attributes & 0x00000400) >> 10 > 0 else '在线' return status # 设置默认打印机 def set_default_printer(device_name): #获取默认打印机的名称 device_name 打印机名称 default_printer_handle = win32print.GetDefaultPrinter() # 判断是否默认打印机 if default_printer_handle != device_name: # 设置默认打印机 win32print.SetDefaultPrinter(device_name)
from win32con import DC_PAPERNAMES,DC_PAPERSIZE # 打印机首选项页面设置的名称 pagenames = win32print.DeviceCapabilities(device_name, 'LPT1', DC_PAPERNAMES) # 打印机首选项页面设置的尺寸 pagesizes = win32print.DeviceCapabilities(device_name, 'LPT1', DC_PAPERSIZE) for k, v in zip(pagenames, pagesizes): value = f'{v["x"]}毫米 x {v["y"]}毫米'