CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2011
    Posts
    45

    Print HTML stream directly from C++ code

    I’m writing a Windows Form application in C++ that creates a complex table that I create as an HTML stream and then display it in a WebBrowser component.

    I know that I can save that stream to disk, open it in a browser, change the printer setting to landscape, and then print the resulting page. That is a lot of manual work.

    Is there a way to print the HTML stream directly from my code while changing the printer parameters?

    Is there a way to print the WebBrowser component if that is needed to change the HTML in printable format?

    I know you can use "this->WebBrowser1->Print();", but how do you force it print in landscape? Is there an HTML code or C++ code.
    Last edited by PapaGeek; May 31st, 2015 at 11:34 AM.

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Print HTML stream directly from C++ code

    Quote Originally Posted by PapaGeek View Post
    I know you can use "this->WebBrowser1->Print();", but how do you force it print in landscape? Is there an HTML code or C++ code.
    You may call WebBrowser1->ShowPageSetupDialog() to have the user make the correct page setup prior to printing, or WebBrowser1->ShowPrintDialog() to initite printing with the opportunity for the user to specify the desired page setup. This is a little less complicated compared to opening your HTML in an external browser.

    I don't see any clean way with the WebBrowser control to non-interactively specifying your desired page setup and then initiate printing. You may, however, be able to hack your way through by calling WebBrowser1->ShowPageSetupDialog() and then manipulating the dialog displayed by means of accessibility API (if available) or things like sending window messages or the like, much like the "good" ol' VB-ish SendKeys way. But that not only is a technique I wouldn't really recommend; since I assume WebBrowser::ShowPageSetupDialog() is a blocking method, you will probably get into further complications regarding multithreading and the window messages vs. worker thread conflict.

    Unfortunately, the WebBrowser control doesn't suppot the DrawToBitmap() method, which might have opened a way to a less hackish approach.

    You'd probably be much more flexible with an approach entirely avoiding HTML (at least as the core data format), as already alluded to in http://forums.codeguru.com/showthrea...21#post2174221. That way you could gain complete control about your printed output by using a System::Drawing::Printing::PrintDocument object. (Ok, you may also use that with the HTML core data representation, doing your own HTML rendering. But that sounds terribly complicated to me as well.)
    Last edited by Eri523; June 1st, 2015 at 11:47 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured