我知道以前有人问过这个问题,但没有明确的答案。
如何以编程方式更改打印机托盘?
我正在尝试使用 python 批量打印一些 PDF。我需要从不同的纸盘打印不同的页面。打印机是理光2232C。有没有办法通过 Acrobat Reader 命令行参数来完成?我能够使用 Win32 api 找出哪些 bin 对应于哪些 binname,但仅此而已。任何建议/捷径/等?
最佳答案
好的,我想通了。答案是:
1.您需要一台本地打印机(如果您需要打印到网络打印机,请下载驱动程序并将其添加为本地打印机)
2.使用win32print获取和设置默认打印机
3.同样使用win32print,使用如下代码:
import win32print
PRINTER_DEFAULTS = {"DesiredAccess":win32print.PRINTER_ALL_ACCESS}
pHandle = win32print.OpenPrinter('RICOH-LOCAL', PRINTER_DEFAULTS)
properties = win32print.GetPrinter(pHandle, 2) #get the properties
pDevModeObj = properties["pDevMode"] #get the devmode
automaticTray = 7
tray_one = 1
tray_two = 3
tray_three = 2
printer_tray = []
pDevModeObj.DefaultSource = tray_three #set the tray
properties["pDevMode"]=pDevModeObj #write the devmode back to properties
win32print.SetPrinter(pHandle,2,properties,0) #save the properties to the printer
- 就这样,托盘已经换好了
使用 Internet Explorer 完成打印(来自 Graham King 的博客)
from win32com import client import time ie = client.Dispatch("InternetExplorer.Application") def printPDFDocument(filename): ie.Navigate(filename) if ie.Busy: time.sleep(1) ie.Document.printAll() ie.Quit()
完成
关于python - 切换打印机托盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/544923/