Printing

Fredrik Lundh fredrik at pythonware.com
Tue Dec 21 08:58:38 CET 2004


Jim & Joanne Collins wrote:

> I've completed a semester of computer programming in Python
> and one thing we didn't learn was how to send data to a windows
> printer instead of the screen.  I've also asked this question in one
> of the Python help places and received about three responses.
> None of them worked.

since you didn't tell us what responses you've always gotten, I guess
I have to provide more than three...

- write directly to the printer device (PRN, LPT1)

- write the output to a temporary file, and use the "print" command
to send it to the printer

    out = open("temp.out", "w")
    ...
    out.close()
    os.system("print /D:LPT1 temp.out")

- use the win32 extensions, and talk to the GDI and spooler functions (see
  Windows API documentation for details).

- use a printer aware UI toolkit, and draw on the printer instead of the screen

- use ReportLab or any other PDF-generating toolkit, and use Acrobat to
  print it.  (same as the second alternative, but generates nicer output):

    os.system("start acrord32.exe /t /h temp.pdf printer")

if you try any of these and it doesn't work, let us know which one, and
what happened.

</F> 






More information about the Python-list mailing list