python - 切换打印机托盘

标签 python winapi

我知道以前有人问过这个问题,但没有明确的答案。

如何以编程方式更改打印机托盘?

我正在尝试使用 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
  1. 就这样,托盘已经换好了
  2. 使用 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/

相关文章:

python - 如何更改 python Mayavi 的窗口标题?

c - GetMenuString 返回空字符串

c++ - 是否可以在不影响其他行的情况下更改编辑控件的字体?

c++ - 64 位 Windows API 结构对齐导致命名管道上的访问被拒绝错误

python - 如何在Python中删除从字符串到特定字符的所有内容

python - 如何连续生成一个范围内的值?

python - 在python中调用外部命令并将值插入到命令中

winapi - XamlCompiler错误WMC1006 : Cannot resolve Assembly or Windows Metadata file 'Microsoft.Win32.Registry.dll'

windows - Windows 上的 OpenGL 1.0 和 1.1 函数指针

python - 不会为自定义用户模型保存配置文件数据