[win32com] Print html

Alex Martelli alex at magenta.com
Mon Aug 14 11:51:22 EDT 2000


"Bill Scherer" <Bill.Scherer at VerizonWireless.com> wrote in message
news:3997F205.3034BBBF at VerizonWireless.com...
    [snip]
> > > 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.
>
> Yup, this works fine.  The only snag I found is that I have to put a small
> delay between the Navigate call and the ExecWB call (time.sleep(1)).

Not very reliable; it would, I think, be better to wait for
document-complete.

Unfortunately, the document-complete event is not currently working (sigh).
See separate thread about that; I've managed to reproduce the problem but
not to diagnose it, yet; something is eating the document-complete,
before-navigate, and navigate-complete events, only when the event handler
is Python (they get received all right by a generic event handler written in
C++/ATL).

The best temporary work-around is probably to loop *checking that the
ReadyState becomes 4*, which means completion.  This will let you print
documents which take a long time arriving, too.  Alternatively, you could
hook another event, which tells you about what's happening to commands
(are they enabled/disabled), but if I were you I would avoid events until
and unless they're fixed or you're truly stuck without them; the "busy loop"
in this case, where you can check say every 0.1 seconds, is not too bad.
Inelegant, but pragmatically OK.


> Being IE, this call will print doc files, too.  I expect that should work
for
> any file that ie can display via an embedded com server...

Yes, any ActiveDocument should work if it's set up that way (to let the
IE user print it out with File/Print, say).  Basically, IE is, among many
other
useful things, an excellent generic container for documents, controls, etc,
and it seems to be that you're using it in this capacity here (plus, as an
HTML renderer when the document is specifically an HTML one; of
course, the HTML rendering is actually performed by another component,
but IE houses that component [a control] "transparently" for you).


> Thanks for your help!

You're most welcome!


Alex






More information about the Python-list mailing list