WebView2 fit to page

DanM55 0 Reputation points

I am using a WebView2 control in a WinForms app. It is working fine. However, I'd like the "Fit to Page" button sizing to be the default when a PDF file is displayed in the WebView2 control. How do I make this the default setting in my VB.net code?

An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,601 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 27,001 Reputation points Microsoft Vendor

    Hi @DanM55 ,

    You can setting the zoom level to "Fit to Page" by default by executing JavaScript code once the WebView2 control is initialized.

    webView21.CoreWebView2.ExecuteScriptAsync("document.body.style.zoom = 'fit-to-width';")

    Best Regards.

    Jiachen Li

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.