printing HTML or PDF from Python

Donnal Walter donnal at donnal.net
Tue Oct 26 11:33:41 EDT 2004


We want to be able to print HTML or PDF files to a given printer from 
Python in a kind of batch mode (without opening a preview window or 
printer dialog for each file). The printer is on a network, but for 
testing purposes I have connected it to my desktop via LPT1. I can 
easily print a text file from Python using:

os.system("copy some.txt LPT1")

And as expected, using this function with "some.html" simply prints the 
html source. (But I tried it anyway. :-) I presume that one would need 
to go through a Web browser of some kind to print the formatted document 
(using CSS, BTW), but we don't want the user to see the browser window, 
or be required to click on the Print button, etc. Is there a way to do 
this from a Python script? We are currently deployed on Windows, but 
would like to keep the application cross-platform if possible. We have 
Mozilla installed, for example, if that would be of use, but I've 
searched the Mozilla mailing list archives without seeing anything about 
printing via Mozilla without actually opening a browser window.

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.

Regards,
Donnal Walter
Arkansas Children's Hospital





More information about the Python-list mailing list