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 » Thu Jan 24, 2013 11:25 am

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: 14314
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxHtmlWindow - Printing?

Post by doublemax » Thu Jan 24, 2013 11:40 am

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 » Thu Jan 24, 2013 1:16 pm

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: 14314
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxHtmlWindow - Printing?

Post by doublemax » Thu Jan 24, 2013 3:09 pm

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 » Thu Jan 24, 2013 11:06 pm

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: 14314
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxHtmlWindow - Printing?

Post by doublemax » Thu Jan 24, 2013 11:21 pm

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 » Fri Jan 25, 2013 1:23 am

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 » Fri Jan 25, 2013 7:36 am

Right, thanks.
It'll take time but I'm sure I'll figure something out eventually.

User avatar
tierra
Site Admin
Site Admin
Posts: 1341
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: wxHtmlWindow - Printing?

Post by tierra » Sat Jan 26, 2013 6:16 pm

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 » Sat Jan 26, 2013 10:09 pm

Well thanks tierra, do you have another solution?

User avatar
doublemax
Moderator
Moderator
Posts: 14314
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxHtmlWindow - Printing?

Post by doublemax » Sun Jan 27, 2013 12:41 am

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: 1341
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: wxHtmlWindow - Printing?

Post by tierra » Wed Jan 30, 2013 6:58 pm

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