printing (again!!)

Benji York benji_york at
Thu Jun 27 15:18:28 CEST 2002

"Geoff Tarrant" <geoff at> wrote in message news:<afcusp$66r$1 at>...
> 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

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)

happy-printing-ly y'rs,

Benji York
benji_york at

More information about the Python-list mailing list