-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controlling the print dialog/window #42
Comments
Thanks for the detailed request! We are actually making the change to allow ExecuteScript even when JS is disabled in IWebView2Settings since we trust the host app knows what it is doing. So I'm not aware of any way to intercept a print job for the cases you mentioned, so have to think through this a bit more. We will also need to work with the UWP WebView2 folks to understand the security implications of virtual printers (cc @adambarlow). |
I think that is a good decision.
I think a Re SVG and PNG: Obviously JS
Likewise for PDF: The JS Re priorities: Although I'd appreciate having the |
Correct me if I'm wrong, but doesn't issue #7 need to be reopened (or otherwise addressed here in issue #42) because the current implementation of Currently If I'm not mistaken, in order to fix this, the entire Win32 print dialog must be ripped out of WebView2, and deleted, and replaced with an event that notifies the WinUI side of WebView2 to display the standard WinUI/UWP printing GUI. I hope my message isn't written in a confusing manner. To clarify, I'm talking about the following print dialog. Currently WebView2 displays this Chromium Win32 print dialog: The above screenshot shows the current print dialog but that is Chromium's old/obsolete Win32 code that doesn't work (won't ever work) in Windows Phone 10 or any other UWP devices, as far as I know. It seems like the best plan would be to delete the current print dialog source code in WebView2 and instead use an event to notify the upcoming WinUI side of WebView2 to display the standard WinUI/UWP printing GUI. This could be incorporated into a larger plan to delete all of the old Win32 GUI code in WebView2 because all of that is obsolete and doesn't work in any UWP desktop computers, laptops, tablets, or smartphones when running WebView2 in modern UWP apps. This issue isn't limited to UWP. It's also applicable to WebView2 running in WPF apps and in WinForms apps. Chromium's old Win32 print dialog (and all other Win32 GUI displayed by Chromium/WebView2) doesn't work with:
|
We don't have support for UWP, WPF, or WinForms yet. For each of these when we do if we have an issue with print we can open issues for them then. Thanks |
Hi, Is there an open issue for this for the winforms version yet? I came here because we're swapping our webbrowser to this new control, and this javascript print opens the print dialog in the tiny area we use for display instead of as a modal dialog (system print dialog), as we're used to and prefer. Thanks! |
the platform has requests around converting html or other web content into pdf, which would benefit from this feature being implemented. See microsoft/react-native-windows#7723 |
I have two fundamental issues with the Print Dialog concept in WebView2:
So these two reasons mean I can’t use the control. I raised these issues over 2 years ago and nothing has changed to my knowledge? |
Exactly my observation. A crippling limitation. It is as if the assumption is the control is full screen and if it were, why not just use a browser? Since the control is advertised for using in apps it needs to address this problem. I agree that the browser should display a system print window will option to maximise like it used to. Or make current one support this. |
+1 for the issue of the daft print settings dialog that gets rendered within the WebView2 component, rather than appearing as a modal dialog. Our team has had a requirement this week for displaying HTML pages in one of our WPF desktop apps, so this issue with WebView2 is disappointing to say the least. Unfortunately the WPF WebBrowser component is no better - still no Print() method (although bizarrely the Winforms version does). Printing via js is possible but WebBrowser doesn't have a print settings dialog. (I also looked at CefSharp, but wasn't happy with 600Mb+ of redistributable assemblies!). |
+1 There is no way that I can see to programmatically set the available options and print to a physical printer (other than using say UI automation to script the dialog when it appears) - is there a workaround? |
We're currently working on a print API (no ETA yet). Until then the only two work arounds are using |
Hi all, we've completed our design for the https://github.com/MicrosoftEdge/WebView2Feedback/pull/2604/files! Please review the pull request and add any feedback you have about this API. We appreciate your input and support! |
Hi all, we have shipped Print APIs as experimental in the 1.0.1414 pre-release package: https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes?tabs=dotnetcsharp#experimental-features. Please let us know if you have any feedback! |
When I print a pdf file to Microsoft PDF using PrintAsync() I get a blank page and that's it. How does one print a pdf file? |
@MikeCheel This is a known issue with PrintAsync which is printing a blank page for PDFs, we are tracking the bug here #3007 |
Thank you for your quick reply |
When I print a DOCX file to Microsoft PDF using PrintAsync() I get a blank page and that's it. How does one print a DOCX file? |
@santey12 I assume browser/system print dialog isn't supported to print a DOCX file hence PrintAsync prints a blank page. One can use |
This is useful. We can then prevent our app from closing by looking to see if this api call returns true or not. |
@ajtruckle You can also use JS beforePrint afterPrint to determine whether print is started/completed or cancelled and control closing the app. |
@monica-ch I like the idea, as you suggested something similar for another ticket #3266. But I struggle with it you see. I have two classes:
It seems to do nothing. If I display the PrintUI and hit cancel, nothing happens. |
@monica-ch Researching tge internet about those two events implies they only fire as indicated. Print started. Print ended. So doesn’t account for cancel window. I think a simply IsPrintUIVisible is much easier 😀 |
@ajtruckle Same code works from our sample app. It gets invoked when I believe Print ended here when print dialog is closed (with successful print or cancelled) |
@monica-ch Alright, so why is my attempt failing? 🤔 |
@liminzhu wrote:
That's great. We'll be among the people using that feature. However, considering that the above technique uses
ExecuteScript
, will printing always still work if EcmaScript is disabled? I'm referring to WebView2 having a setting equivalent toWindows.UI.Xaml.Controls.WebViewSettings.IsJavaScriptEnabled
, that is put_IsScriptEnabled.For this reason, I suggest adding a simple "OpenPrintDialog" method to the API, even if it is implemented by doing exactly the same as the
ExecuteScript
snippet above. The advantages of "OpenPrintDialog" are:ExecuteScript
technique works, it is obscure and will leave people wondering/asking: How to print?Can you make a "ClosePrintDialog" method in WebView2 that closes any print dialog/window that may be open? (Does nothing if no print dialog is currently open.) Related: If a WebView2 XAML element has it's
Visibility
property set toCollapsed
, or if the WebView2 element is removed/detached from the element tree, what happens to the print dialog? If it remains visible because it's in a separate floating window, then the "ClosePrintDialog" method would be especially useful to solve problems here.Can you make a "IsPrintDialogOpen" method that returns a boolean indicating whether the/any print dialog/window is open/displayed/visible?
Can you make an event that is triggered when the print dialog/window is closed? Ideally the event arguments would include a boolean that specifies whether or not the dialog was closed via the Cancel button/key/action. An extra bonus feature would be the inclusion of a background print job identifier in the arguments of this event.
When the user closes the print dialog by clicking the "Print"/"OK" button, is it possible to intercept the print job settings and change them and/or cancel the print job? Reasons include:
Virtual printers that print to files
When using a virtual printer named "Print to PDF" or "Save as PDF", when it prompts for the file name and location, and when it runs in a UWP app, have the security rules already been tested successfully? Meaning, will it enforce the same security rules as
Windows.Storage.Pickers.FileSavePicker
even when running via a separate-process mode?In our kiosk system, we must prevent kiosk users seeing the local file system. Therefore, would it be possible to make the following boolean settings in WebView2?
Examples of the virtual printers that exist in Windows are:
Alternative designs include:
Summary
WebView.CaptureSelectedContentToDataPackageAsync
but with ability to capture entire page.AB#27694507
The text was updated successfully, but these errors were encountered: