-
Notifications
You must be signed in to change notification settings - Fork 0
/
printing_win.py
40 lines (35 loc) · 1.31 KB
/
printing_win.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import string
import subprocess
import win32print, win32ui
from config import current_config
from PIL import Image, ImageWin
print_command = 'rundll32 C:\Windows\System32\shimgvw.dll ImageView_PrintTo "${filename}" "${printer}"'
printers = ['sinfonia']
print_count = 0
def print_image(photo_name):
global print_count
if current_config.args.win_env:
photo_name = photo_name.replace(r'\\', r'\\\\')
print("win_filename: '%s'" % photo_name)
print_count += 1
if len(printers) > 1:
printer_name = printers[print_count % 2]
else:
printer_name = printers[0]
#command = string.Template(print_command).safe_substitute(filename=photo_name, printer=printer_name)
#command = command.replace(r'\\', r'\\\\')
#print("executing: '%s'" % command)
if not current_config.args.test_image:
#win32api.ShellExecute (0, "print", photo_name, '/d: "%s"' % printer_name, ".", 0)
#subprocess.call(command.split(' '))
dc = win32ui.CreateDC()
dc.CreatePrinterDC(printer_name)
photo = Image.open(photo_name)
dc.StartDoc(photo_name)
dc.StartPage()
dib = ImageWin.Dib(photo)
x1, y1, x2, y2 = 0, 0, 1280, 1920
dib.draw(dc.GetHandleOutput(), (x1, y1, x2, y2))
dc.EndPage()
dc.EndDoc()
dc.DeleteDC()