wxHtmlWindow - Printing?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
dominover
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Sep 23, 2012 3:00 am

wxHtmlWindow - Printing?

Post 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
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxHtmlWindow - Printing?

Post by doublemax »

You can't print any widget directly. In this case, use wxHtmlEasyPrinting::PrintText() and pass the HTML code from from your wxHtmlWindow.
Use the source, Luke!
dominover
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Sep 23, 2012 3:00 am

Re: wxHtmlWindow - Printing?

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxHtmlWindow - Printing?

Post 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
Use the source, Luke!
dominover
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Sep 23, 2012 3:00 am

Re: wxHtmlWindow - Printing?

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxHtmlWindow - Printing?

Post 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.
Use the source, Luke!
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: wxHtmlWindow - Printing?

Post 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)
"Keyboard not detected. Press F1 to continue"
-- Windows
dominover
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Sep 23, 2012 3:00 am

Re: wxHtmlWindow - Printing?

Post by dominover »

Right, thanks.
It'll take time but I'm sure I'll figure something out eventually.
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: wxHtmlWindow - Printing?

Post 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.
dominover
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Sep 23, 2012 3:00 am

Re: wxHtmlWindow - Printing?

Post by dominover »

Well thanks tierra, do you have another solution?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxHtmlWindow - Printing?

Post 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.
Use the source, Luke!
User avatar
tierra
Site Admin
Site Admin
Posts: 1355
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: wxHtmlWindow - Printing?

Post 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.
Post Reply