WebView2删除pdf上方的空间(工具栏)
我正在WebView2控件中加载PDF,这是我的代码:
Imports Microsoft.Web.WebView2.Core
Public Class Form1
Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddHandler webView.CoreWebView2InitializationCompleted, AddressOf WebView_CoreWebView2InitializationCompleted
AddHandler webView.NavigationCompleted, AddressOf WebView_NavigationCompleted
Await InitializeAsync()
End Sub
Private Sub WebView_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs)
End Sub
Private Async Function InitializeAsync() As Task
Await webView.EnsureCoreWebView2Async(Nothing)
webView.Source = New Uri("file:///D:/123.pdf")
End Function
Private Sub WebView_CoreWebView2InitializationCompleted(ByVal sender As Object, ByVal e As Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs)
webView.CoreWebView2.Settings.HiddenPdfToolbarItems = CoreWebView2PdfToolbarItems.None
End Sub
End Class
现在我想删除PDF上方的黑空间(工具栏),查看:
I am loading PDF in WebView2 control, here is my code:
Imports Microsoft.Web.WebView2.Core
Public Class Form1
Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddHandler webView.CoreWebView2InitializationCompleted, AddressOf WebView_CoreWebView2InitializationCompleted
AddHandler webView.NavigationCompleted, AddressOf WebView_NavigationCompleted
Await InitializeAsync()
End Sub
Private Sub WebView_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs)
End Sub
Private Async Function InitializeAsync() As Task
Await webView.EnsureCoreWebView2Async(Nothing)
webView.Source = New Uri("file:///D:/123.pdf")
End Function
Private Sub WebView_CoreWebView2InitializationCompleted(ByVal sender As Object, ByVal e As Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs)
webView.CoreWebView2.Settings.HiddenPdfToolbarItems = CoreWebView2PdfToolbarItems.None
End Sub
End Class
Now I want to remove the black space (toolbar) that is above that PDF, look:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来这是一个Winforms项目,但是根据您的屏幕截图,我认为您可能会错误地设置WebView2控件,例如 this ,您提到的问题发生在WebView2 Control不会铺平整个窗口时。
因此,您需要确认WebView2控件的大小及其在整个窗口中的显示方式,例如:
It looks like this is a winforms project, but based on your screenshots, I think you may have the webView2 control set up incorrectly, something like this, the issue you mentioned occurs when the WebView2 control does not tile the entire window.
So you need to confirm the size of the WebView2 control and how it will appear in the entire window, like this: