Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print functionality in WebView2 control

Thanks in Advance !

In my application, I have embedded a WebView2 control inside a WPF usercontrol.

Is there anyway or a workaround that can help me to take a print of the WebView2 control ?

I identified that the current WebView2 pre-release SDK provided by Microsoft does'nt have any thing specific to print functionality.

like image 216
DotNetSpartan Avatar asked Jun 30 '20 09:06

DotNetSpartan


2 Answers

As a workaround for HTML documents you can inject script that calls the DOM print method. For example if in the following the webview2 is the WPF WebView2 class:

await webview2.CoreWebView2.ExecuteScriptAsync("window.print();");

Otherwise, we have some feature requests regarding printing in WebView2 Feedback, like this:

Controlling the print dialog/window

like image 123
David Risney Avatar answered Nov 18 '22 05:11

David Risney


WebView2 supports printing to PDF with PrintToPdfAsync(path, settings):

await webView2.CoreWebView2.PrintToPdfAsync(@"Path/To/File.pdf");
like image 4
haldo Avatar answered Nov 18 '22 04:11

haldo