我有一个用Python打印PDF文件的脚本 .
该脚本使用 win32api.ShellExecute()
工作,一切都很好,但现在,我需要打印具有双面内容的PDF文件,具体用户手册 .
我尝试在win32print中设置双工模式,但没有任何作用,打印机仍然在2张纸上打印2页用于PDF而不是双面打印两页 . 打印机在其他应用程序中使用此模式,但python脚本不能正常工作 . 这是我用来打印的代码的一部分:
name = win32print.GetDefaultPrinter()
printdefaults = {"DesiredAccess": win32print.PRINTER_ALL_ACCESS}
handle = win32print.OpenPrinter(name, printdefaults)
level = 2
attributes = win32print.GetPrinter(handle, level)
attributes['pDevMode'].Duplex
attributes['pDevMode'].Duplex = 1
win32print.SetPrinter(handle, level, attributes, 0)
win32print.GetPrinter(handle, level)['pDevMode'].Duplex
win32api.ShellExecute(0,'print','file.pdf','.','/route',0)
知道为什么这不起作用吗?谢谢 .
1 回答
尝试运行此代码:
它适用于我的计算机:Windows 10,Python 2.7.14,pypiwin32-220
笔记:
在我的计算机上,PRINTER_ACCESS_ADMINISTER在OpenPrinter中导致'Access is denied' .
在我的计算机上,SetPrinter失败,'Access is denied' . 但'Duplex'设置正确..