gpt4 book ai didi

c# - 让 CefSharp 正确处理 WPF 中的 PDF 文件

转载 作者:太空宇宙 更新时间:2023-11-03 12:37:09 25 4
gpt4 key购买 nike

此问题不会影响 WinForms。

我已经从 github 站点下载了最简单的示例:

https://github.com/cefsharp/CefSharp.MinimalExample

据我所知,一切都是最新的——我已经使用 NuGet 来确保安装了最新的 CefSharp.Common、CefSharp.Wpf 等——当前版本为 53。

当我用它浏览网页时,它很好。问题是当我尝试查看基于 PDF 的页面时,例如:

http://www.cbu.edu.zm/downloads/pdf-sample.pdf

所以在 MainWindow.xaml 中,我将“地址”属性绑定(bind)到这个值而不是“www.google.com”:

<Window x:Class="CefSharp.MinimalExample.Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
Title="{Binding Path=Title, ElementName=Browser, Converter={StaticResource TitleConverter}}"
WindowState="Maximized">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<wpf:ChromiumWebBrowser Grid.Row="0"
x:Name="Browser"
Address="http://www.cbu.edu.zm/downloads/pdf-sample.pdf" />
<StatusBar Grid.Row="1">
<ProgressBar HorizontalAlignment="Right"
IsIndeterminate="{Binding IsLoading, ElementName=Browser}"
Width="100"
Height="16"
Margin="3" />
<Separator />
<!-- TODO: Could show hover link URL here -->
<TextBlock Text="{Binding Address, ElementName=Browser}"/>
</StatusBar>
</Grid>

当我运行示例时,为了导航到此 PDF,屏幕保持空白并且进度控件不更新:

enter image description here

... 除非我执行取消最大化浏览器窗口或移动它等操作,否则我可以查看它:

enter image description here

在此之后还有另一个奇怪的问题,即滚动条和 +/- 按钮似乎没有响应。我注意到,例如,如果我按下“+”按钮,然后执行另一个操作(例如最大化/恢复),那么似乎已经执行了预期的“+”操作。同上滚动条和其他操作。

对于 WinForms 最小示例,它不会表现出这种行为,如果这有帮助,只有 Wpf。

非常感谢任何建议。

最佳答案

这已作为问题 #1799 的副本在 GitHub 站点上提出:

WPF/OffScreen PDF Viewer not working #1799

在版本 55 发布之前,网站上所述的解决方案是:

“建议的解决方法是按照 ceforum 上的建议在计时器上调用 Invalidate()

您可以回滚到 51 并使用 disable-surfaces 或等待版本 55 发布。"

我发现回滚到以前的版本对我很有效。

2019 年 1 月 21 日更新

这不再是最新版本的 CefSharp 的问题。

关于c# - 让 CefSharp 正确处理 WPF 中的 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40505140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com