Text printing under Windows

Alan Miller ajm at enteract.com
Thu Mar 29 20:33:48 EST 2001


Gabriele Favalessa (ego at macondo.visconti.home) wrote:
>how do I print using a dot matrix printer in text mode under Windows
>98?  I have both a local and a remote printer.

For local printers, other people have pointed out that you just open the 
device and dump data directly to it.  For networked printers that you 
have a UNC name for, you can do much the same - the following code works 
just fine:
>>> myprinter = open(r"\\myserver\myprinter", "wb")
>>> myprinter.write("Here is my test string\n")
>>> myprinter.close()

There's also a way to open a locally-defined print queue (e.g. "HP 
LaserJet 5si in the back room") and dump data directly to it, but the 
required APIs aren't complete in Mark Hammond's win32print extensions.  
I've looked at extending them and mentioned it to Mark once, but haven't 
made the time to do so.  

The missing API calls are StartDocPrinter, WritePrinter and EndDocPrinter 
if anyone's interested; I also have a VB class that I put together to 
nicely encapsulate this if anyone wants a copy of it.  Sending raw data 
to a print queue doesn't actually seem to be all that urgent for most 
people - I did it because I needed to dump pregenerated PS and PCL files 
and was getting sick of running "copy x.ps \\servername\printername" in 
command windows.

ajm



More information about the Python-list mailing list