In my WinUI 3.0 - UWP project, I have a WebView2
control that displays a simple html as follows. But when I call the following javascript
code using ExecuteScriptAsync (as shown below), I get the following error:
Error:
Check your printer or select another printer. The printer you chose isn't available or isn't installed correctly.
Screenshot of Error:
Remarks: There is nothing wrong on my Windows 10's default Print to PDF
printer as I can print the exact same html page from a browser (MS Edge or Google).
Question: What I may be doing wrong here, and can we resolve the issue? I think a cause of the issue may have something to do with how I'm using the JavaScript in my html and/or how I'm passing a parameter to the ExecuteScriptAsync(...)
method. Note: wvTest
, as you may have guessed, is the name of WebView2 control.
Code:
//Correctly displays the html page with a simple text: `Test paragraph`
private async void myButton_Click(object sender, RoutedEventArgs e)
{
string sHTML = "<!DOCTYPE html>" +
"<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">" +
"<head>" +
"<meta charset=\"utf-8\" />" +
"<title>Test Title</title>" +
"</head>" +
"<body>" +
"<p>Test paragraph</p>" +
"<script> window.print();</script>" +
"</body>" +
"</html>";
//System.Diagnostics.Debug.WriteLine(sHTML);
wvTest.NavigateToString(sHTML);
}
//This event opens the Print Dialog
with the message shown above:
private async void btnPrint_Click(object sender, RoutedEventArgs e)
{
await wvTest.ExecuteScriptAsync(javascriptCode: "window.print();");
}
UWP
. – StokeSave Tags
button. I re-did it now. – StokePrinter
selection (shown in the image above) is not letting you see the other choices. I don't know why because all the code I have is shown all in this post. I have not set any printer options in the code. However, if I print the same html manually from a browser, the printer gives all other options to select. Maybe, it's happening sinceWinUI 3.0
is still in preview until this November. However, according to this GitHub post, thewindow.print();
should work. – Stoke