使用 Microsoft Webview2 控件将 PDF 绘制到 WPF 应用程序中
Draw on a PDF into a WPF applicartion using Microsoft Webview2 control
我正在开发一个 WPF 应用程序,我想在其中打开并绘制成 pdf。
我可以在 webview2 控件中打开 pdf,但无法“绘制到 pdf 中”
(如果我通过 Microsoft Edge 打开此 pdf 是可能的)
有没有人idea/hint/suggestion为什么在我编译代码时绘图功能disabled/not处于活动状态?
Desired Output
Output
已用资源:
Get started with WebView2 in WPF
Using the WebView2 control in a .Net application
**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 重现该问题。我认为 the resource link you provide 中的屏幕截图来自以前版本的 WebView2。在当前版本的 WebView2 中,绘图、突出显示和擦除似乎被禁用。
我唯一能找到的相关 API 是 pdf 工具栏中的 HiddenPdfToolbarItems
which is added in the latest WebView2 prerelease. But this API can only hide/show these buttons。
我认为我们不能使用代码来制作绘图、突出显示和擦除显示,因为没有相关的API。您可以提供有关此问题的反馈 here。我想 Edge WebView 团队会检查并回复。
我正在开发一个 WPF 应用程序,我想在其中打开并绘制成 pdf。
我可以在 webview2 控件中打开 pdf,但无法“绘制到 pdf 中”
(如果我通过 Microsoft Edge 打开此 pdf 是可能的)
有没有人idea/hint/suggestion为什么在我编译代码时绘图功能disabled/not处于活动状态?
Desired Output
Output
已用资源: Get started with WebView2 in WPF
Using the WebView2 control in a .Net application
**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 重现该问题。我认为 the resource link you provide 中的屏幕截图来自以前版本的 WebView2。在当前版本的 WebView2 中,绘图、突出显示和擦除似乎被禁用。
我唯一能找到的相关 API 是 pdf 工具栏中的 HiddenPdfToolbarItems
which is added in the latest WebView2 prerelease. But this API can only hide/show these buttons。
我认为我们不能使用代码来制作绘图、突出显示和擦除显示,因为没有相关的API。您可以提供有关此问题的反馈 here。我想 Edge WebView 团队会检查并回复。