[win32com] Print html

Alex Martelli alex at magenta.com
Mon Aug 14 08:07:59 EDT 2000


"Bill Scherer" <Bill.Scherer at VerizonWireless.com> wrote in message
news:3997DBBF.E727F1DB at VerizonWireless.com...
> Alex Martelli wrote:
>
> > "Bill Scherer" <Bill.Scherer at VerizonWireless.com> wrote in message
> > news:39945697.F47A13EE at VerizonWireless.com...
> > > Hello,
> > >
> > > I'm looking for a way to automate printing html on win32 with python.
> > > Currently, I'm able to load IE5 as a com object and get it to load a
> > > document.
> > > I can get the document object from the IE5 object.
> > > Neither object seems to have a print method of any kind.
> > > Any ideas?
> >
> > IWebBrowser2::ExecWB takes as its first parameter the
> > OLECMDID (numeric code) of the command you want IE to
> > execute.
>
> OK, where does  IWebBrowser2 com from?

It's one of the interfaces implemented by a browser-object.  What you
call the "IE5 object" should expose this method, among many others.

> This is how I get my handle to IE:
>     I ran makepy.py for shdocvw.dll
>     import win32com.client
>     ie = win32com.client.Dispatch("InternetExplorer.Application.1")

So ie.ExecWB(6,2) should work just fine, I think.

> While I'm at it, navigating and getting a doc is like so:
>     ie.Navigate("<some uri>")
>     doc = ie.Document

Yep.    This should also work fine.

> > OLECMDID_PRINT =  6 is the one you want.
> >
> > The second parameter encodes the options; for example,
> > OLECMDEXECOPT_DONTPROMPTUSER = 2 to proceed without a
> > confirmation prompt to the user.
>
> These constants are definded in the module generated by makepy...

So you can also use:

    ie.ExecWB(win32com.constants.OLECMDID_PRINT,
        win32com.constants.OLECMDEXECOPT_DONTPROMPTUSER)

if you prefer that to ie.ExecWB(6,2).  It's certainly clearer what this
does,
as the constant names have some hints in them.


> > I think you don't need to specify the 3rd and 4th
> > parameters, but, do experiment.


Alex






More information about the Python-list mailing list