好的,我想通了.答案是:
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
Run Code Online (Sandbox Code Playgroud)
使用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()
Run Code Online (Sandbox Code Playgroud)完成
归档时间: |
|
查看次数: |
3770 次 |
最近记录: |