We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

How do I print to a Windows printer?

Tim Golden writes:

It all depends what you’re trying to print, what tools you have at your disposal, and how much control you need.

  • If you simply have a “document” (read: file of a well-known type, associated with one application) you wish to print, and aren’t too fussy about controlling, then you can use the ShellExecute approach. This works (assuming you have the corresponding applications installed) for Microsoft Office documents, PDF files, text files, and pretty much any major application. Try it and see.
  • The next most general case is where you have something, for example a text file or raw PCL, which you know you can send directly to a printer. In that case, you can use the win32print functions directly.
  • If you have an image to print, you can combine the power of the Python Imaging Library with the win32ui module to do a rough-and-ready but useful print to any printer.
  • If you have a fair amount of text to print, your best bet is to use the Reportlab PDF Toolkit and its Platypus document system to generate readable PDFs from any amount of text, and then use the ShellExecute technique to print it.

For details, see http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html

CATEGORY: windows