0

In my project we were using WebBrowser control and it has print html functionality implemented by using below code, as you all know IE is no more supported I am replacing WebBrowser control with WebView2 in my WPF application.

 IOleServiceProvider sp = webBrowser1.Document as IOleServiceProvider;
            if (sp != null)
            {
                Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
                Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E");
                const int OLECMDID_PRINT = 6;
                const int OLECMDEXECOPT_DONTPROMPTUSER = 1;

                dynamic wb; // will be of IWebBrowser2 type, but dynamic is cool

                sp.QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, out wb);
                if (wb != null)
                {

                    wb.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, null, null);

                }
            }

When I replaced the WebView2 and try to achieve the same functionality, I replaced the above code with webBrowser1.ExecuteScriptAsync("window.print();"). Unable to achieve the same and there is no Document object associated the WebView2.

  • Please see this other [stackoverflow question on WebView2 Printing](https://stackoverflow.com/questions/62654738/print-functionality-in-webview2-control/62662770?noredirect=1#comment128787931_62662770). – David Risney Dec 07 '22 at 17:42

0 Answers0