Skip to content Skip to sidebar Skip to footer

How To Change Printer Preference Settings Using Python

I'm new to python and want to change the printer preference settings. I'm using win32print library and need to change PyDEVMODE Object properties given on link http://timgolden.me.

Solution 1:

This code will obviously give error.

As you are using pDevModeObj before its creation. Even in next line, you are not assigning value to pDevModeObj but rather assigning variable pDevModeObj to properties["pDevMode"], which does not work in Python.

The fix to your existing solution would be:

PRINTER_DEFAULTS = {"DesiredAccess":win32print.PRINTER_ALL_ACCESS}  
pHandle = win32print.OpenPrinter('300LN1', PRINTER_DEFAULTS)  
properties = win32print.GetPrinter(pHandle, 2)
pDevModeObj = properties["pDevMode"]
pDevModeObj.Orientation = 2  
win32print.SetPrinter(pHandle,2,properties,0)
win32print.ClosePrinter(pHandle)

Post a Comment for "How To Change Printer Preference Settings Using Python"