This time is really out of practical needs , Want to use python Write a little script
The boss sent me a copy containing hundreds of personal information pdf file , If you open documents one by one , Click Print, I feel like I want to see dazzle .
It is found that calling a computer program requires win32 This library , And at first glance, I found that this library is very NB, How do you say , This library can interact with computers , For example, a prompt box pops up , Or call some programs built in the system . Too wide a range , And it's not the purpose of learning , Let's talk about it later .
install win32, It's just pip install pywin32 Or the following one is installed through the image of Douban
pip install -i http://pypi.douban.com/simple/ pywin32 --trusted-host pypi.douban.com
Other methods are similar to ,pip Installation doesn't say much
Checking data , Basically, the following code will be used for discovery
import win32print
import tempfile
import win32api
def print_file(filename):
open(filename,"r")
win32api.ShellExecute(
0,
"print",
filename,
'/d:"%s"' % win32print.GetDefaultPrinter(),
".",
0
)
We need to pay attention to , In this code filename It should be the file path , Specific to documents
C:\Users\mik\Desktop\py_word\11.pdf
path = r"C:\Users\mik\Desktop\ Print "
for i in os.listdir(path):
file_path = os.path.join(path,i)
print(" The document you want to print is %s"%i)
print_file(file_path)
if i.endswith(“docx”):
print_file(file_path)
2020.10.23