切换打印机托盘 [英] Switching Printer Trays

查看:36
本文介绍了切换打印机托盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I know this question has been asked before, but there was no clear answer.

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

How do I change the printer tray programmatically?

我正在尝试使用 python 批量打印一些 PDF.我需要从不同的托盘打印不同的页面.打印机是理光2232C.有没有办法通过 Acrobat Reader 命令行参数来实现?我可以使用 Win32 api 找出哪些 bin 对应哪些 binname,但仅此而已.有什么建议/捷径/等吗?

I am trying to use python to batch print some PDFs. I need to print different pages from different trays. The printer is a Ricoh 2232C. Is there a way to do it through and Acrobat Reader command line parameter? I am able to use the Win32 api to find out which bins correspond to which binnames, but that is about it. Any advice/shortcuts/etc?

推荐答案

好的,我想通了.答案是:

1.你需要一台本地打印机(如果需要打印到网络打印机,请下载驱动程序并添加为本地打印机)
2.使用win32print获取和设置默认打印机
3.同样使用win32print,使用如下代码:

Ok, I figured this out. The answer is:

1. you need a local printer (if you need to print to a network printer, download the drivers and add it as a local printer)
2. use win32print to get and set default printer
3. also using win32print, use the following code:

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 的博客)

  1. that's it, the tray has been changed
  2. printing is accomplished using internet explorer (from Graham King's blog)

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()

完成

这篇关于切换打印机托盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆