本帖最后由 52pjtyw 于 2024-2-27 13:39 编辑
下发的打印任务到打印机队列了,状态也是已发送到打印机,但是无法触发打印,是什么情况。
[Python] 纯文本查看 复制代码 import win32print
def print_file(filename):
# 打开文件
with open(filename, "rb") as f:
data = f.read()
printer_name = win32print.GetDefaultPrinter()
# 打印文件
hPrinter = win32print.OpenPrinter(printer_name)
try:
hJob = win32print.StartDocPrinter(hPrinter, 1, ("test", None, "RAW"))
try:
win32print.StartPagePrinter(hPrinter)
win32print.WritePrinter(hPrinter, data)
win32print.EndPagePrinter(hPrinter)
finally:
win32print.EndDocPrinter(hPrinter)
finally:
win32print.ClosePrinter(hPrinter)
path = r'C:\Users\admin\Desktop\新建DOC文档.pdf'
print_file(path) |