python - 如何使用python按顺序打印文档?
问题描述
我正在使用包来打印文档。根据打印类型,我有两个不同的文件夹。用于单面打印的文件夹 1 和用于双面打印的文件夹 2 。这是通过 win32api 包获得的,但问题是顺序打印。win32api
python
attributes['pDevMode'].Duplex
用于设置打印模式。1 用于单面,2 用于双面。最终是文件夹名称。
win32api.ShellExecute(0,'print',file_path,'.','/route',0)
打印文档但不按顺序打印。
所以我从这里开始关注其他解决方案。这给了我这个错误
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("------",file_path,"-----")
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,'print',file_path,'.','/route',0)
shell.ShellExecuteEx(fmask = win32com.shell.shellcon.SEE_MASK_NOASYNC, lpVerb='print', lpFile=file_path, lpParameters=name)
win32print.ClosePrinter(handle)
print("-----DONE FOLDEFR-------------")
print("--------DONE PRINTING-------")
解决方案
推荐阅读
- ios - SwiftUI 表格:与 navigationBarItems 不一致的表格行为
- javascript - 画布圆圈未正确绘制
- c++ - 如何使用 cv::cuda 和 C++ 应用 Canny Edge 检测器?
- visual-studio-code - 用户输入后源代码无效时如何自动完成?
- c++ - C++中链表的重载运算符+=
- python - 将 tabula-py 更新到最新版本
- r - 在汇总(dplyr)中使用特定值而不将其过滤掉
- ios - 如果用户输入了密码,则更改初始 ViewController
- angular - 获取在 Angular 中的组件上注册的事件列表
- java - 检查源级别 AnnotationProcessors 中 Element 的继承