Postscript printing in Python

Fred L. Drake, Jr. fdrake at acm.org
Thu Sep 23 11:13:11 EDT 1999


Clement writes:
 > I need to do a mail merge to a postscript printer.  Does anyone know of
 > any tools that is available to the Python community?   
 > 
 > I checked the libraries and other Python documentation and failed to
 > find any help on printing to a postscript printer!

  It's not clear what you want.  Can't you just open a connection to
the printer and write to it?  The API will differ by platform; on Unix 
you'd do something like:

      import os
      printer = os.popen("lpr", "w")

      printer.write("%!PS-Adobe-2.0\n")
      ...
      printer.close()

  I imagine you can get some sort of handle to a printer on Windows
that allows similar operations.
  On the other hand, you may want something a little higher level.
Grail (http://grail.python.org/) includes support for printing to a
PostScript printer (Unix-style) via an extended "writer" object; see
the formatter module in the standard library for a description of the
interface.  It's pretty easy to use, but may not be what you're
looking for.  Adapting it to work on Window shouldn't be too hard if
you can get a way to send the PostScript to the printer yourself.


  -Fred

--
Fred L. Drake, Jr.	     <fdrake at acm.org>
Corporation for National Research Initiatives




More information about the Python-list mailing list