printing HTML or PDF from Python

Peter Hansen peter at engcorp.com
Tue Oct 26 12:14:45 EDT 2004


Donnal Walter wrote:
> os.system("copy some.txt LPT1")
> And as expected, using this function with "some.html" simply prints the 
> html source. 

That's of course because the printer knows how to handle "raw" text
without further help.  As you surmised, anything more complicated
needs either native support (e.g. Postscript can be sent to a
Postscript printer naturally), or an application to be launched
to interpret the file and "draw" it for the printer.

> The same more or less goes for PDF files. We have Acrobat Reader 
> installed, but I can't see how to print a PDF file from Python via AR 
> without opening the file inside the reader and manually printing each 
> one. Any suggestions would be much appreciated.

I don't think you'll find a cross-platform approach to handle
all your needs, but there are a few options.  The only one
that I'm familiar with at all would be using ActiveX to
control IE (for HTML files) and Acrobat Reader (for PDF)
through the documented interfaces.  From Python it's not
generally very hard to do this, and I suspect the archives
have examples.  (I haven't done the printing part myself, but
have done lots of IE-through-ActiveX and it's pretty
straightforward.)

-Peter



More information about the Python-list mailing list