printing (again!!)

Benji York benji_york at cknainc.com
Thu Jun 27 09:18:28 EDT 2002


"Geoff Tarrant" <geoff at galtar.co.uk> wrote in message news:<afcusp$66r$1 at newsg2.svr.pol.co.uk>...
> I want to use Python as the language in a Computing course that I teach.
> However, I can't find a way that is relatively straightforward to send data
> to a printer in a Windows environment.

If you have a recent win32all installed, then the function below will
send plain text (requires both carrage returns and line feeds) to the
printer.  You can also throw in some PCL if you like, but for more
complex stuff I would use some of the suggestions seen elsewhere in
this thread (PDF or wxPython (especially it's HTML printing
functions)).


import win32print

def rawPrint(data, jobName, printerName=None):
    if printerName == None:
        printerName = win32print.GetDefaultPrinter()

    printerHandle = win32print.OpenPrinter(printerName)
    printJob = win32print.StartDocPrinter(printerHandle, 1,
                                          (jobName, None, None))
    win32print.WritePrinter(printerHandle, data)
    win32print.EndDocPrinter(printerHandle)
    win32print.ClosePrinter(printerHandle)



happy-printing-ly y'rs,

Benji York
benji_york at cknainc.com



More information about the Python-list mailing list