add win32.send_data_to_printer() function
This commit is contained in:
parent
33cf50c4cb
commit
51a0a490ea
3 changed files with 29 additions and 0 deletions
6
docs/edbob.win32.rst
Normal file
6
docs/edbob.win32.rst
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
:mod:`edbob.win32`
|
||||
==================
|
||||
|
||||
.. automodule:: edbob.win32
|
||||
:members:
|
|
@ -27,6 +27,7 @@ The following pages describe the ``edbob`` package from a caller's perspective.
|
|||
edbob.modules
|
||||
edbob.sqlalchemy
|
||||
edbob.util
|
||||
edbob.win32
|
||||
|
||||
|
||||
To-Do
|
||||
|
|
|
@ -33,6 +33,7 @@ if sys.platform == 'win32': # docs should build for everyone
|
|||
import pywintypes
|
||||
import win32file
|
||||
import winerror
|
||||
import win32print
|
||||
|
||||
|
||||
def RegDeleteTree(key, subkey):
|
||||
|
@ -106,3 +107,24 @@ def file_is_free(path):
|
|||
finally:
|
||||
if handle:
|
||||
win32file.CloseHandle(handle)
|
||||
|
||||
|
||||
def send_data_to_printer(data, printer_name, job_name):
|
||||
"""
|
||||
Create and submit a new print job (named ``job_name``) which sends ``data``
|
||||
directly to the Windows printer identified by ``printer_name``. Returns
|
||||
the number of bytes actually written to the printer port.
|
||||
|
||||
This is designed for sending command strings to Zebra label printers, but
|
||||
could potentially be useful for other situations as well.
|
||||
"""
|
||||
|
||||
printer = win32print.OpenPrinter(printer_name)
|
||||
assert printer
|
||||
assert win32print.StartDocPrinter(printer, 1, (job_name, None, None))
|
||||
win32print.StartPagePrinter(printer)
|
||||
num_bytes = win32print.WritePrinter(printer, data)
|
||||
win32print.EndPagePrinter(printer)
|
||||
win32print.EndDocPrinter(printer)
|
||||
win32print.ClosePrinter(printer)
|
||||
return num_bytes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue