如何解决如何使用python打印文档?
我正在使用 win32api
python
软件包来打印文档。根据打印类型,我有两个不同的文件夹。 单面打印的文件夹1和双面打印的文件夹2。这是通过win32api软件包获得的,但问题是顺序打印。
attributes['pDevMode'].Duplex
用于设置打印模式。 1表示单面, 2表示双面。最终是文件夹名称。
win32api.ShellExecute(0,'print',file_path,'.','/route',0)
,但不按顺序打印文档。
所以我跟随了其他SOLUTION FROM HERE。 这给了我这个错误
shell.ShellExecuteEx(fmask = win32com.shell.shellcon.SEE_MASK_NOASYNC,lpVerb='print',lpFile=file_path,lpParameters=name)
NameError: name 'win32com' is not defined
代码如下
import win32api
import win32print
import os
import win32com.shell.shell as shell
# https://stackoverflow.com/questions/47435973/print-pdf-file-in-duplex-mode-via-python
#https://stackoverflow.com/questions/18025882/how-to-determine-if-win32api-shellexecute-was-successful-using-hinstance
Base_Path = os.path.dirname(os.path.realpath(__file__))
name = win32print.GetDefaultPrinter()
print("------Base_Path-->",Base_Path,"-----")
print("-----GetDefaultPrinter--->",name,"-----")
for folder in "12":
src = os.path.join(Base_Path,"admin",folder)
for file in sorted(os.listdir(src)):
file_path = os.path.join(src,file)
print("------","-----")
printdefaults = {"DesiredAccess": win32print.PRINTER_ALL_ACCESS}
handle = win32print.OpenPrinter(name,printdefaults)
level = 2
attributes = win32print.GetPrinter(handle,level)
attributes['pDevMode'].Duplex
attributes['pDevMode'].Duplex = int(folder)
win32print.SetPrinter(handle,level,attributes,0)
win32print.GetPrinter(handle,level)['pDevMode'].Duplex
#win32api.ShellExecute(0,0)
shell.ShellExecuteEx(fmask = win32com.shell.shellcon.SEE_MASK_NOASYNC,lpParameters=name)
win32print.ClosePrinter(handle)
print("-----DONE FOLDEFR-------------")
print("--------DONE PRINTING-------")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。