Printing from wx.lib.iewin.IEHtmlWindow

Hello,

I built an application that uses a Cheetah template as a template for a report. The app allows the end-user to choose the parameters of the report, then fills in the template, generating an HTML document. Under wxPython 2.4, I was using a wx.html.HtmlWindow to display the page, and was using standard buttons and events to allow the end user to print the page.

Moving to 2.5, the rendering engine in wx.html.HtmlWindow has changed, and my page no longer renders the same. In short, yuck. I am trying to use wx.lib.iewin.IEHtmlWindow in its place, as IE renders my page reasonably well. However, I can not figure out how to tell the IEHtmlWindow to print. I know I can right-click on the window and choose Print... from the context menu, but I'd like to be able to do this with a clearly-labeled button. Is there a way to send a print command to the window? Would that be the normal wx.Printer, wx.Printout way? I was using wx.html.HtmlEasyPrinting on the old version.

Alternately, is there a way to show the IE menu and/or toolbars? I noticed a ShowBrowserBar method, but it takes parameters that I don't know anything about.

Thanks in advance for your help,

---Peter Herndon

So I found the following bit of code (not certain what language) that
theoretically causes IE to print:

VAr vain, vaOut: OleVariant;
begin
    MyWebBrowser.ControlInterface.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, vain, vaOut);
end

This is tantalizing as the iewin object provides the needed ExecWB
method. However, from the source for iewin I see:

# ExecWB
# retType: VT_VOID
# params:
# cmdID
# in:True out:False optional:False type:unsupported type
29
# cmdexecopt
# in:True out:False optional:False type:unsupported type
29
# pvaIn
# in:True out:False optional:False type:VT_VARIANT
# pvaOut
# in:True out:True optional:True type:VT_VARIANT

Unsupported type 29 doesn't sound promising. Further, I have no idea
what should be passed for pvaIn.

Regards,
Cliff

···

On Wed, 2004-09-15 at 13:08 -0400, T.Peter Herndon wrote:

However, I can not figure out how to tell the
IEHtmlWindow to print. I know I can right-click on the window and

--
Cliff Wells <clifford.wells@comcast.net>

Okay, apparently you should be able to pass None as pvaIn, and the
values for OLECMDID_PRINT and OLECMDEXECOPT_DONTPROMPTUSER are 6 and 2,
respectively, so the following seems like it might work:

ExecWB(6, 2, None, None)

Unfortunately it bombs with an exception about 'unsupported type' for
argument 0, so I'm not sure what the problem is. I know almost nothing
about Windows/ActiveX so I don't have any further info to offer.

Regards,
Cliff

···

On Wed, 2004-09-15 at 13:19 -0700, Cliff Wells wrote:

# ExecWB
# retType: VT_VOID
# params:
# cmdID
# in:True out:False optional:False type:unsupported type
29
# cmdexecopt
# in:True out:False optional:False type:unsupported type
29
# pvaIn
# in:True out:False optional:False type:VT_VARIANT
# pvaOut
# in:True out:True optional:True type:VT_VARIANT

Unsupported type 29 doesn't sound promising. Further, I have no idea
what should be passed for pvaIn.

--
Cliff Wells <clifford.wells@comcast.net>

Thank you, Cliff. I tried a couple of similar methods, without success. I noticed that IEHtmlWindow has a method, ShowBrowserBar(self, pvaClsid, pvarShow, pvarSize=None). I figured it might be interesting to see what happens when I turn on the browser bar, as there's a Print button on my IE toolbar. I also noticed that IEHtmlWindow also has a method, GetCLSID(self), which looks like a fit for the pvaClsid argument in ShowBrowserBar. I pop it in and get an Unsupported object type error. It occurs to me that there's probably some IE-as-ActiveX-control documentation somewhere on MSDN. I'll see if I can track it down, but I'm beginning to think I'm encroaching on territory where the ROI for wrapping some of these classes in wxPython is simply not enough to justify Robin's effort. I suspect I'm going to fall back on win32com-based COM automation of a Word template. It'll wind up looking prettier anyway.

Any thoughts on the matter?

Thanks again,

---Peter

···

On Sep 15, 2004, at 4:42 PM, Cliff Wells wrote:

On Wed, 2004-09-15 at 13:19 -0700, Cliff Wells wrote:

# ExecWB
# retType: VT_VOID
# params:
# cmdID
# in:True out:False optional:False type:unsupported type
29
# cmdexecopt
# in:True out:False optional:False type:unsupported type
29
# pvaIn
# in:True out:False optional:False type:VT_VARIANT
# pvaOut
# in:True out:True optional:True type:VT_VARIANT

Unsupported type 29 doesn't sound promising. Further, I have no idea
what should be passed for pvaIn.

Okay, apparently you should be able to pass None as pvaIn, and the
values for OLECMDID_PRINT and OLECMDEXECOPT_DONTPROMPTUSER are 6 and 2,
respectively, so the following seems like it might work:

ExecWB(6, 2, None, None)

Unfortunately it bombs with an exception about 'unsupported type' for
argument 0, so I'm not sure what the problem is. I know almost nothing
about Windows/ActiveX so I don't have any further info to offer.

Regards,
Cliff

Did you try the

rundll32.exe mshtml.dll,PrintHTML "http://www.google.com"

technique? Worked for me.

···

On Wed, 2004-09-15 at 18:10 -0400, T.Peter Herndon wrote:

Thank you, Cliff. I tried a couple of similar methods, without
success. I noticed that IEHtmlWindow has a method,
ShowBrowserBar(self, pvaClsid, pvarShow, pvarSize=None). I figured it
might be interesting to see what happens when I turn on the browser
bar, as there's a Print button on my IE toolbar. I also noticed that
IEHtmlWindow also has a method, GetCLSID(self), which looks like a fit
for the pvaClsid argument in ShowBrowserBar. I pop it in and get an
Unsupported object type error. It occurs to me that there's probably
some IE-as-ActiveX-control documentation somewhere on MSDN. I'll see
if I can track it down, but I'm beginning to think I'm encroaching on
territory where the ROI for wrapping some of these classes in wxPython
is simply not enough to justify Robin's effort. I suspect I'm going to
fall back on win32com-based COM automation of a Word template. It'll
wind up looking prettier anyway.

Any thoughts on the matter?

--
Cliff Wells <clifford.wells@comcast.net>

Did you try the

rundll32.exe mshtml.dll,PrintHTML "http://www.google.com"

technique? Worked for me.

No I didn't, as I don't see how it applies. To clarify, I'm not printing a web page on the network, I'm using an HTML string as a report template and interpolating values. From there I'm feeding the HTML string to IEHtmlWindow using LoadString() in order to render it, and trying to print the rendered page. I'm working this way because a rendered HTML page is an easy-to-create substitute for a "hard-core" report definition language, as long as the rendering looks okay. If need be, I will use Word, or PIDDLE's PDFgen in place of HTML, it's just not going to be as easy.

I suspect I'm misunderstanding how to apply the rundll32.exe technique, could you clarify for me?

Thanks again,

---Peter

No, I just misunderstood what you were trying to accomplish.

Have you considered ReportLab?

http://www.reportlab.org/

http://phaseit.net/claird/comp.text.pdf/PDF.html

Regards,
Cliff

···

On Thu, 2004-09-16 at 08:37 -0400, T.Peter Herndon wrote:

> Did you try the
>
> rundll32.exe mshtml.dll,PrintHTML "http://www.google.com"
>
> technique? Worked for me.
>
>
No I didn't, as I don't see how it applies. To clarify, I'm not
printing a web page on the network, I'm using an HTML string as a
report template and interpolating values. From there I'm feeding the
HTML string to IEHtmlWindow using LoadString() in order to render it,
and trying to print the rendered page. I'm working this way because a
rendered HTML page is an easy-to-create substitute for a "hard-core"
report definition language, as long as the rendering looks okay. If
need be, I will use Word, or PIDDLE's PDFgen in place of HTML, it's
just not going to be as easy.

I suspect I'm misunderstanding how to apply the rundll32.exe technique,
could you clarify for me?

--
Cliff Wells <clifford.wells@comcast.net>

T.Peter Herndon wrote:

Thank you, Cliff. I tried a couple of similar methods, without success. I noticed that IEHtmlWindow has a method, ShowBrowserBar(self, pvaClsid, pvarShow, pvarSize=None). I figured it might be interesting to see what happens when I turn on the browser bar, as there's a Print button on my IE toolbar. I also noticed that IEHtmlWindow also has a method, GetCLSID(self), which looks like a fit for the pvaClsid argument in ShowBrowserBar. I pop it in and get an Unsupported object type error. It occurs to me that there's probably some IE-as-ActiveX-control documentation somewhere on MSDN. I'll see if I can track it down, but I'm beginning to think I'm encroaching on territory where the ROI for wrapping some of these classes in wxPython is simply not enough to justify Robin's effort.

As I mentioned in the Migration Guide the wx.activex module can only handle parameter and return types for the basics (bool, int, float, string and None) but it should be able to be expanded to handle more types including other IDispatch COM types and etc. I don't really have the time or the COM experience to do it, but I'm hopeful that somebody will and will contribute their work to the project.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Have you considered ReportLab?

http://www.reportlab.org/
IBM Developer
Cameron Laird's personal notes on PDF

Yes, I'm evaluating it now, as well as Word automation. The neat bit about my earlier solution is that I have a Cheetah template that I can easily edit, if I need to make changes to the layout of the report. ReportLab has in it somewhere a means of generating PS or PDF from HTML, so that processing chain might still work. I considered ReportLab when I began the original project, but wanted the easiest possible solution, and generating PDFs from scratch would have been a lot harder than the HTML route. Having a template that is editable by a knowledgeable end-user has no small value, though, so the Word direction has a certain appeal.

Thanks for your advice,

---Peter

I think the technique you want to use it to generate the HTML and then
convert it to PDF.

http://phaseit.net/claird/comp.text.pdf/PDF_converters.html#html2ps

···

On Fri, 2004-09-17 at 10:20 -0400, T.Peter Herndon wrote:

> Have you considered ReportLab?
>
> http://www.reportlab.org/
> IBM Developer?
> loc=dwmain
> Cameron Laird's personal notes on PDF
>
>

Yes, I'm evaluating it now, as well as Word automation. The neat bit
about my earlier solution is that I have a Cheetah template that I can
easily edit, if I need to make changes to the layout of the report.
ReportLab has in it somewhere a means of generating PS or PDF from
HTML, so that processing chain might still work. I considered
ReportLab when I began the original project, but wanted the easiest
possible solution, and generating PDFs from scratch would have been a
lot harder than the HTML route. Having a template that is editable by
a knowledgeable end-user has no small value, though, so the Word
direction has a certain appeal.

--
Cliff Wells <clifford.wells@comcast.net>