I've been sitting on this problem for a while now and still can't wrap my head around it. I have the code below but I can't even really test it because I do not have access to administrator permissions. Whenever I try the win32print.SetPrinter function I get an "Access Denied" error which I can fix by entering the console as admin but the program needs to run without admin permissions when it's done. There obviously are programs that can print without admin permissions so there has to be a way.
file_path = 'path\\test.ps'
printer_name = win32print.GetDefaultPrinter()
file_handle = open(file_path, 'rb')
printer_handle = win32print.OpenPrinter(win32print.GetDefaultPrinter())
info = win32print.GetPrinter(printer_handle, 2)["pDevMode"]
if (win32print.DocumentProperties(0, printer_handle, printer_name, info, info, 5) == 1):
win32print.SetPrinter(printer_handle, 2, info, 0)
job = win32print.StartDocPrinter(printer_handle,1,("postscripttest",None,"RAW"))
print(win32print.GetJob(printer_handle, job))
win32print.WritePrinter(printer_handle,file_handle.read())
win32print.EndDocPrinter(printer_handle)
win32print.ClosePrinter(printer_handle)
else:
print("Process Cancled")
I am a bit lost as to where I could look. First I was really happy when win32print.DocumentProperties with mode 5 gave me an interface where I could set the printer options, which is exactly what I need, and it also saved the changes in "info", a DevMode object. However, I can't think of another way to actually "Save" those settings than with SetPrinter. And as I said before, SetPrinter requires Admin perms, unless there is a different way to use it that I don't know of.
For a TL;DR: I need to be able to change the printer settings for one printer job without admin permissions. Just a simple one page printer job from a postscript file where I can set the options for how the printer is supposed to print beforehand.
Any help is highly appreciated. It really seems like there is practically nobody who knows their stuff with python and printers.
from How to change settings of a printer without admin permissions - python
No comments:
Post a Comment