-
Notifications
You must be signed in to change notification settings - Fork 54
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Can we have hidden WebView2 and still invoke Printing? #3266
Comments
I originally asked this question here: #1485. And, in that question I was redirected to: #1331. But, whilst a Print API has now been developed, my questions remain:
I really would like to move on with implementing WebView2 in my application and these queries were originally raised in July 2021. I appreciate there is much to do! Any sample code of the main concepts appreciated. Thanks. |
I am open to suggestions to make this easier. For example:
What ever is easiest to implement that still looks nice from a users perspective. Thanks for your help! |
Thanks for reaching out. I've assigned this to a dev that can help follow up on this. |
Thank you! At first I tried to create a second invisible browser control:
As you can see, I have commented the code out. It did not work. Because when I tried to do my own printing, the first thing I did was to navigate to my printer version of the schedule and try to print. No joy. |
From my research it seems that it is not possible to use a WebView2 control in a hidden state because it is not fully initialised until it is displayed. Can we do this then?
|
@ajtruckle Yes you can open the printable version of the schedule in a webview2 popup, invoke the print dialog and use JS afterprint that fires when printing is started (~when user click Print button) or cancelled and close the popup. |
@monica-ch Thanks for confirming. Can you please guide me on the steps involved for Win32 API? |
@monica-ch I came up with a partially successful solution:
This code re-uses the same browser control. But I don't know how to use the JS |
We have ExecuteScript API that runs JS code. In the
|
Hi @monica-ch Thanks. I have changed the logic to avoid the need to do an update afterwards. So that simplifies it. So, step 1, how do I used ExecuteScriot to create the pop up window, maximised to the display, and invoke the print up? What’s the code for that? Thanks. When the print finishes / cancels what I need it to do is close this pop up window we created I appreciate the example provided but I need a little more help to understand the correct code. Thank you. |
You might have to do something like below.
|
Hi @monica-ch ! Thanks for the code / explanations. Beginning with the first step, I tried:
I call this function on demand for now, once I have something on the display. But, running this code alone appears to do nothing. 🤔 I get no errors and no popup on screen. Why? I thought that would happen at this stage. In-fact, if I use the sample WebView2 app and use Inject Script on the Script menu:
|
Hi @monica-ch |
@ajtruckle Yes, please specify a valid URL. |
@monica-ch Slowly getting there:
If I use a literal url like |
@monica-ch Got the first step working! Now on to next. 😊 |
@monica-ch So I have managed to do the first bit like this:
I could adjust it to take the work area instead to maximize to screen. But the window should be maximized anyway. It seemed just a little simpler. My problem with the sample code is that it is using
|
@monica-ch I have come up with a compromise. I added a new "Full Screen" button to my editor. So if they want to print and would like a bigger area to work with, they click the button to get the bigger view. Then, they right-click and invoke Print. It sets us to where we want to be with a couple of mouse clicks and no extra code. Personally, I would like to add for the team to consider extending the ShowPrintUI, when using the browser dialog, to have a second parameter - display on maximixed popup window. This means anyone can use it if they need to and will be useful for CDialog users like me. But I am happy with this compromise of showing a maximized popup to the dialog size. I may change to use screen size. |
Hi @monica-ch Can I please ask the status of this ticket? Will any of my ideas be put on the feature list and tracked? |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Environment: MFC / Win32 / CDialog
My current program uses
CHtmlView
. I have aCHtmlView
attached to my dialog. On this control I display an "editor" version of a schedule. I can replicate this behaviour using a WebView2 control.When the user wants to print, it currently does this:
CHtmlView
CHtmlView
if they cancel printing.CHtmlView
when they shut my program down (if it exists).So:
Thank you for your guidance for this as I do not know how to do any of this. I only know how to create the initial WebView2 attached to my
CDialog
which has the editors' version of the schedule.Thank you in advance for taking me through the essential steps of what is involved.
The text was updated successfully, but these errors were encountered: