-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyrawprint.py
33 lines (29 loc) · 959 Bytes
/
pyrawprint.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
import os, sys
import win32print
def send_raw_data_to_printer(raw_data, printer_name):
print(f">>> arg printer name: {printer_name}")
if not printer_name:
printer_name = win32print.GetDefaultPrinter()
print(f">>> Using printer {printer_name}")
hPrinter = win32print.OpenPrinter(printer_name)
try:
hJob = win32print.StartDocPrinter(hPrinter, 1, ("test of raw data", None, "RAW"))
try:
win32print.StartPagePrinter(hPrinter)
win32print.WritePrinter(hPrinter, raw_data)
win32print.EndPagePrinter(hPrinter)
except:
e = sys.exc_info()[0]
print(e)
finally:
win32print.EndDocPrinter(hPrinter)
except:
e = sys.exc_info()[0]
print(e)
finally:
win32print.ClosePrinter(hPrinter)
def get_printers():
return [
p[2] for p in
win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL)
]