printing (again!!)
Martin Franklin
mfranklin1 at gatwick.westerngeco.slb.com
Wed Jun 26 15:51:46 EDT 2002
On Wednesday 26 Jun 2002 5:57 pm, Geoff Tarrant wrote:
> 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 I can't find a way around this,
> I will have to revert to Delphi or VB. Please help. I like the idea of
> sending 20 or so Python programmers to University each year.
>
> Geoff Tarrant
Geoff,
Get hold of the excelent win32 extension for python (url????)
Then somthing like this: (untested since I wrote it about a year or two ago!)
import win32print
printer_list=[]
for p in win32print.EnumPrinters(win32print.PRINTER_ENUM_CONNECTIONS):
printer_list.append(p[2])
for p in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL):
printer_list.append(p[2])
default_printer=win32print.GetDefaultPrinter()
printer = win32print.OpenPrinter(default_printer)
jid = win32print.StartDocPrinter(printer, 1, ('Page %i' %copy, None, 'RAW'))
bytes=win32print.WritePrinter(printer, open(file, 'rb').read())
win32print.EndDocPrinter(printer)
win32print.ClosePrinter(printer)
Please not this is sending a file's contents to the printer (as it happens a
postscript file)
Cheers
Martin
More information about the Python-list
mailing list