Skip to content
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

[Problem/Bug]: CoreWebView2PrintSettings.ScaleFactor is not working #4082

Closed
ahmetaksoy1985 opened this issue Oct 19, 2023 · 15 comments
Closed
Assignees
Labels
bug Something isn't working regression Something used to work but doesn't anymore tracked We are tracking this work internally.

Comments

@ahmetaksoy1985
Copy link

ahmetaksoy1985 commented Oct 19, 2023

What happened?

Previously, I didn't need to set "CoreWebView2PrintSettings.ScaleFactor" because "CoreWebView2.PrintToPdfAsync" was automatically scaling perfectly. However, after a recent Edge Browser update, the auto-scale feature disappeared. I had to start manually adjusting "CoreWebView2PrintSettings.ScaleFactor". Unfortunately, now, with the Edge 118 update, the scale factor no longer works as expected. It's not a WinUI3 WinAppSDK issue. Skia/PDF m117 > m118.

Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

118.0.2088.57

SDK Version

118.0.2088.46

Framework

WinUI3/WinAppSDK

Operating System

Windows 10

OS Version

19045.3570

Repro steps

New WinUI3 1.4.231008000 App
Minimal code:

`string resultFilePath = resultFilePath;
string html = html;
WebView2 webView2 = new WebView2();
webView2.NavigationCompleted += WebView2_NavigationCompleted;
await webView2.EnsureCoreWebView2Async();
webView2.NavigateToString(html);

async void WebView2_NavigationCompleted(WebView2 sender, CoreWebView2NavigationCompletedEventArgs args)
{
CoreWebView2PrintSettings printSettings = webView2.CoreWebView2.Environment.CreatePrintSettings();
printSettings.ScaleFactor = 0.90;
await webView2.CoreWebView2.PrintToPdfAsync(resultFilePath, printSettings);
}`

Regression

Regression in newer Runtime

Last working version (if regression)

117.0.2045.60

AB#47156308

@ahmetaksoy1985 ahmetaksoy1985 added the bug Something isn't working label Oct 19, 2023
@victorhuangwq victorhuangwq added the regression Something used to work but doesn't anymore label Oct 19, 2023
@monica-ch
Copy link
Contributor

@ahmetaksoy1985 Can you check if you can repro the issue with Edge canary and Beta? Seems like no repro with the non stable channels

Once you confirm we'll see how this can be fixed in 118 runtime

@monica-ch monica-ch added the tracked We are tracking this work internally. label Oct 20, 2023
@ahmetaksoy1985
Copy link
Author

It's not working Edge Canary also. Skia/PDF m120. I get the same PDF like the stable channel. It starts after updating Edge Browser. I also tried this another machine. First auto-scale function has gone with an update. Then i have to set scale manually. It was working for a while. Now scale is not working also. I didn't change any code in my app.

@ahmetaksoy1985
Copy link
Author

ahmetaksoy1985 commented Oct 20, 2023

I tried with Microsoft.WebView2.FixedVersionRuntime.117.0.2045.60.x64. It works. CoreWebView2PrintSettings.ScaleFactor adjustments applies to PDF. I set Scale to 0.9. It fits. However, when I don't set Scale, it doesn't auto fit the HTML file to PDF. Previously i could autofit HTML file to PDF perfectly without setting CoreWebView2PrintSettings.ScaleFactor.
I tried with WPF also. I can share my repos if you want.

@monica-ch
Copy link
Contributor

@ahmetaksoy1985 Thanks for the information, looks it I found the issue and working on a fix. Will update the thread once I have a fix, will reach out to you for any info if needed

@ahmetaksoy1985
Copy link
Author

ahmetaksoy1985 commented Oct 20, 2023

Thank you very much. Could you please also fix auto-fit? Previously if the HTML size big it was autoscaling to the PDF.

@zenzeinet
Copy link

zenzeinet commented Oct 26, 2023

Hi, this seems also related to a severe bug in PowerBI Desktop export to PDF feature. When exporting (from the desktop) to PDF, if there are various sizes of pages, the exported PDF is zoomed in and does not show the full information. This has happened to us in multiples machines with different versions of windows and PowerBI Destkop right after the WebView update to 118.0.2088.69. Worked perfectly with 117.x
Related issues: https://community.fabric.microsoft.com/t5/Desktop/Export-to-PDF-error-zoomed-in/m-p/3494459

@monica-ch
Copy link
Contributor

monica-ch commented Oct 26, 2023

@ahmetaksoy1985 This is now fixed in Edge canary channel 120.0.2184.0+. Please test and let us know if you still see issues.

https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel

Also, for your question on auto-fit, could you please open a new issue with us for us to investigate and fix.

@ahmetaksoy1985
Copy link
Author

ahmetaksoy1985 commented Oct 26, 2023

Thank you very much. It's fixed. Auto-fit is also working. I hope it will be resolved in Edge Stable as soon as possible. For now, I've renamed the folder "C:\Program Files (x86)\Microsoft\EdgeWebView" folder to use Edge Canary Webview.

@Zordiac
Copy link

Zordiac commented Nov 10, 2023

Hi, I am facing the same issue. I tried to change the Environment of the WebView 2 to the Edge Canary version like this:

CoreWebView2Environment webView2Environment = await CoreWebView2Environment.CreateAsync(browserExecutableFolder: ".\\Microsoft Edge");

However, it doesn't seem to be using it. Only when I uninstall WebView 119.0 it, uses the edge version that I referenced. Once I install any version of WebView, it reverts to using that one. So the browserExecutableFolder doesn't work (https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel).

Any ideas how I can force it to use the canary version, without having to uninstall webview?

@ahmetaksoy1985
Copy link
Author

Please fix Edge Stable also. I changed "C:\Program Files (x86)\Microsoft\EdgeWebView" folder with Edge Canary Webview files for temporary fix. But when Edge Stable update comes, it brakes again.

@victorhuangwq
Copy link
Collaborator

Hello @Zordiac and @ahmetaksoy1985, thank you for your interest in the fix. The fix is currently in the Canary channel for testing and evaluation. It will be available in the Stable channel once we determine the fix is okay.

As of this message, the Stable channel is on version 119, while the Canary channel is on version 120. The fix will be included in the Stable channel when it reaches version 120.0.2184 or higher.

I hope this helps. Please let me know if you have any questions or feedback.

@Zordiac
Copy link

Zordiac commented Nov 10, 2023

Hi @victorhuangwq,

thanks for clarifying!

I do however have one issue with the canary channel version 120 of microsoft edge. It works on my development machine (by manually changing the browserExecutableFolder to the installation path of the canary version), but not on my other systems. On my production system I get an error message when navigating saying "ConnectionAborted". When I switch back to 119 that message disappears and everything works, except for the scaling of course.
Do you have any suggestion on how I can make this work with the canary version in the meantime?

Thanks

@victorhuangwq
Copy link
Collaborator

Just to the get what you are saying, you basically want to make your production system use the Canary runtime for now?

That is possible, and one way of doing it is this:
https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel#using-an-environment-variable

Basically, it makes the system select the earliest channel (starting from Canary, Dev, Beta then Stable). So if your system has Canary installed, it will select that.

Once 120 reaches stable you can just swap the environmental variable back to the normal order

@Zordiac
Copy link

Zordiac commented Nov 10, 2023

well, the production system doesn't work anyway because webview 118/119 killed the scale feature, so yeah I want to use the canary runtime for now.

But why do I need to set that environment variable? I have provided a full offline version of edge canary 120 with my app. In the app, I have set the browserExecutableFolder to just that canary 120 version. Also, when I run it it says version 120, so it's using the correct canary version. But I get an error message when I navigate to any page.

@victorhuangwq
Copy link
Collaborator

I don't think this is relevant to this current issue - I might need to get someone else to look at it. Please file a bug report so we can track it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Something used to work but doesn't anymore tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

6 participants