我正在开发一个WPF应用程序,我想在其中打开并绘制成pdf。
我可以在webview2控件中打开pdf,但是我不能"绘制"到pdf中。(如果我通过Microsoft Edge打开这个pdf是可能的)
有没有人一个想法/提示/建议为什么绘图功能被禁用/不活跃时,我编译的代码?
所需输出
输出使用资源:在WPF中使用WebView2
在。net应用程序中使用WebView2控件
**Installed versions:**
[Introduction to Microsoft Edge WebView2][1]
[Using the WebView2 control in a .Net application][2]
Installed version of Microsoft.Web.WebView2: 1.0.902.49
Installed version of Microsoft Edge: 92.0.902.67
Installed version of Microsoft Edge WebView2-Runtime: 92.0.902.67
Target Framework: .NET Framework 4.7.2
Visual Studio 2019
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Web.WebView2.Core;
namespace SwissSonic.Pages
{
/// <summary>
/// Interaction logic for Change_drawing.xaml
/// </summary>
public partial class Change_drawing : Page
{
private MainWindow mainWindow;
public Change_drawing(MainWindow main)
{
InitializeComponent();
InitializeAsync();
mainWindow = main;
mainWindow.Button_Click_Zeichnung.Click += Button_Click_Zeichnung;
}
async void InitializeAsync()
{
await webView1.EnsureCoreWebView2Async(null);
}
private void Button_Click_Zeichnung(object sender, RoutedEventArgs e)
{
webView1.CoreWebView2.Settings.IsStatusBarEnabled = true;
webView1.CoreWebView2.Settings.AreDefaultContextMenusEnabled = true;
webView1.CoreWebView2.Settings.IsScriptEnabled = true;
webView1.CoreWebView2.Settings.IsStatusBarEnabled = true;
string test = @"file:\C:\TestPDF\mcdonalds_in_india.pdf";
//string test = @"https://www.stadlerrail.com/media/pdf/web_stadler_rail_gb20_de.pdf";
// webView1.Source = new Uri(test);
webView1.CoreWebView2.Navigate(test);
}
}
}
<Page x:Class="SwissSonic.Pages.Change_drawing"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SwissSonic.Pages"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="Change_drawing">
<Grid Background="Red">
<Grid.RowDefinitions>
<RowDefinition Height="35"/>
<RowDefinition Height="*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<wv2:WebView2 Name="webView1" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" Grid.RowSpan="3"/>
</Grid>
</Page>
我可以用最新版本的WebView2再现这个问题。我认为你提供的资源链接中的截图来自以前版本的WebView2。在当前版本的WebView2中,绘制,高亮和擦除似乎被禁用了。
我能找到的唯一一个相关的API是HiddenPdfToolbarItems
,它是在最新的WebView2预发布版中添加的。但是这个API只能隐藏/显示pdf工具栏中的这些按钮。
我认为我们不能使绘制,高亮和擦除显示使用代码,因为没有相关的API。您可以在这里提供有关此问题的反馈。我想Edge WebView团队会检查并回复。