Page 1 of 1

wxHtmlWindow - Printing?

Posted: Thu Jan 24, 2013 11:25 am
by dominover
I'm having trouble figuring out how to print a wxHtmlWindow called HtmlWindow1 in my application.

I've tried treating it like a file by creating an instance of wxHtmlEasyPrinting class and then accessing the PrintFile method with no success.

I just can't figure out how to print the Html widget in wxWidgets.

Any clues as to how this is done?

Thanks

Re: wxHtmlWindow - Printing?

Posted: Thu Jan 24, 2013 11:40 am
by doublemax
You can't print any widget directly. In this case, use wxHtmlEasyPrinting::PrintText() and pass the HTML code from from your wxHtmlWindow.

Re: wxHtmlWindow - Printing?

Posted: Thu Jan 24, 2013 1:16 pm
by dominover
but what if I don't have html code? I'm trying to print the htmlwindow widget out with all it's contents?

I suppose I should be asking, how do you print a wxWidget?

Re: wxHtmlWindow - Printing?

Posted: Thu Jan 24, 2013 3:09 pm
by doublemax
If you have a wxHtmlWindow, you usually also have the html code (where else would it come from?)

If you were using wxWidgets 2.9.x, use wxWebView instead, which has a Print() method:
http://docs.wxwidgets.org/trunk/classwx_web_view.html

Re: wxHtmlWindow - Printing?

Posted: Thu Jan 24, 2013 11:06 pm
by dominover
I'm using the html window in a different way to normal. Lets's forget the world html It's a white page to me.

I've mounted some widgets to it and will be having those widgets display data in a report. So I basically have an html page in a GUI which contains some numbers and words. No html at all. I've done this because it can be printed like a page and displayed in a GUI. I want to print it. If all this is is 'Printing a Widget' then maybe this is what I should ask. Sorry, but I'm not overly experienced in this area but I'm getting there.

Should a start another thread asking how to print a widget? How do you print a widget?

Re: wxHtmlWindow - Printing?

Posted: Thu Jan 24, 2013 11:21 pm
by doublemax
Should a start another thread asking how to print a widget? How do you print a widget?
The answer will be the same: You can't.

If you want to have something printed, you must be able to draw it to a device context. wxWidgets uses native controls where ever possible. And e.g a button can't draw itself onto a printer device context.

In other words: Whatever screen you created using widgets (can you show a screenshot?), you will have to recreate it with wxDC drawing operations if you want to print it.

You could try to use wxClientDC or wxWindowDC to grab the content of a widget from the screen, but it would probably only work for widgets currently visible and i'm not sure it'll work on all platform. But i've never tried it.

Re: wxHtmlWindow - Printing?

Posted: Fri Jan 25, 2013 1:23 am
by Auria
doublemax is right, with the exception that the newer wxWebView will be able to print widgets (since it uses WebKit/Trident, but of which support printing everything)

Re: wxHtmlWindow - Printing?

Posted: Fri Jan 25, 2013 7:36 am
by dominover
Right, thanks.
It'll take time but I'm sure I'll figure something out eventually.

Re: wxHtmlWindow - Printing?

Posted: Sat Jan 26, 2013 6:16 pm
by tierra
doublemax wrote:You could try to use wxClientDC or wxWindowDC to grab the content of a widget from the screen, but it would probably only work for widgets currently visible and i'm not sure it'll work on all platform. But i've never tried it.
This approach also means you're just printing a bitmap from a screenshot. This can be highly inefficient and very restrictive.

For example, it doesn't scale to high DPI printers, and uses a massive amount of memory it has to transfer to the print job, which is bad for wireless printers.

Re: wxHtmlWindow - Printing?

Posted: Sat Jan 26, 2013 10:09 pm
by dominover
Well thanks tierra, do you have another solution?

Re: wxHtmlWindow - Printing?

Posted: Sun Jan 27, 2013 12:41 am
by doublemax
Can you show a screenshot of what you need to print? Even if you say you don't know html, the view things you need to know to use wxHtmlEasyPrinting can be learned in an hour or less.

Re: wxHtmlWindow - Printing?

Posted: Wed Jan 30, 2013 6:58 pm
by tierra
This has been mentioned a couple times already, but your best option, and the way to do this properly really is to fetch the HTML page from wxHtmlWindow, and pass it over to wxHtmlEasyPrinting.