Tuesday, January 08, 2008

Have you ever need to browse to several pages and print them?  It seems like it should be easy and it is with this little Python script.

I had an Intranet based system that displayed items in a browser.  The manager of the group I built this for asked for a hard copy of every item that fit a certain criteria.  So instead of them going to over 400 pages by hand I just created this simple script. 

It worked like a charm.

#start script

from win32com import client
import time

ie = client.Dispatch("InternetExplorer.Application")

def printPage(url):

    print "printing " + url
    ie.Navigate(url)

    while ie.Busy:
        time.sleep(1)
        print 'navigating...'

    print 'starting print job...'
    ie.ExecWB(6, 2)
    print 'executed print job.'
  
    while ie.Busy:
        time.sleep(1)
        print 'printing...'


printPage("http://google.com")
ie.Quit()

#end script

Sources:

http://www.darkcoding.net/software/printing-word-and-pdf-files-from-python/

http://www.grimsworld.org.uk/printie.html

Tuesday, January 08, 2008 3:44:48 PM (Central Standard Time, UTC-06:00)  #    Comments [0]