WebView2 fit to page

DanM55 0 Reputation points
2024-04-27T14:35:38.2366667+00:00

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?

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

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 31,166 Reputation points Microsoft Vendor
    2024-04-29T07:42:31.4333333+00:00

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.