今天想学习一下怎样用python调用打印机打印文档,网上找了代码如下:
import win32print
import win32com.client
from PIL import Image, ImageWin
#import _imaging
def print_docfile(imagefilename): #打印doc文件
word = win32com.client.DispatchEx(‘kwps.Application’)
#调用word程序
word.Visible = 0
word.DisplayAlerts = 0
#不在前台显示文档及错误,在实际使用阶段可以全部关闭,提高运行速度,但是在调试时打开还是用处挺大的,可以对操作是否实现自己的需求进行直观的判断,比如说我们选中的内容是否已经高亮等等。
doc = word.Documents.Open(imagefilename)
doc.PrintOut()
doc.Close()
imagefilename = ‘d:/dayintupian.docx’
print_docfile(imagefilename)
因为我的机器上只有wps,运行后报错。如下:
*** Remote Interpreter Reinitialized ***
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\d