Business environment
- windows+python
The business process
- Read the network address
- Download the file
- Print local files
Key extensions
- pywin32
Key software
- Foxit pdf( Silent printing key , To make Fuxin pdf The editor becomes pdf Open program by default ,wps It's fine too , But the effect is not good )
Pay attention to the download pdf Is there a path for
Source code
# encoding=utf-8
import win32api
import win32print
import redis
import time
import requests
import chardet
import os
pool = redis.ConnectionPool(host='ip Address ',password=' password ',port=6379)
path_list = redis.Redis(connection_pool=pool)
i=0
while True:
path = path_list.lpop('printing_list')# Read remote pdf Address
if path == None:
time.sleep(3)
else:
time.sleep(1)# Wait for the printer , Prevent too many printing tasks from getting stuck
i=i+1
path=str(path,encoding='utf-8')
down_path = os.getcwd()+"/pdf/"+str(i)+".pdf";
url = "https://******/"+path # Network file address
r = requests.get(url)
with open(down_path,"wb") as f: #wb: Write a file in binary form
f.write(r.content) #r.content: Read files in binary mode
win32api.ShellExecute(0,"print",down_path,'/d:"%s"' % win32print.GetDefaultPrinter(),".",0)
print(path);