在不使用 WindowsFormsHost 的情况下在 WPF 中查看 PDF

发布于 2025-01-03 18:37:30 字数 386 浏览 0 评论 0原文

是否有用于显示 PDF 的本机 WPF 控件?我正在编写一个程序,该程序将加载 PDF 文件,然后在其顶部显示额外的注释。

使用 WindowsFormsHost (http://hugeonion.com/2009/04/06/displaying-a-pdf-file-within-a-wpf-application/) 将不起作用,因为 WindowsFormsHost 控件始终显示在所有其他控件之上窗口中的 WPF 控件。这不会让我的注释在 PDF 上被看到。

将 PDF 转换为具有我需要的缩放细节级别的光栅图像会创建一个太大的文件。

WebBrowser 控件不允许以编程方式更改或缩放页面。我也无法删除 Adob​​e 工具栏。

我使用的任何第三方库都需要免费(例如啤酒)。

Are there any native WPF controls for displaying PDFs? I am writing a program that will load a PDF file and then display extra notations on top of it.

Using a WindowsFormsHost (http://hugeonion.com/2009/04/06/displaying-a-pdf-file-within-a-wpf-application/) won't work because a WindowsFormsHost control always displays on top of all other WPF controls in a window. This won't allow my notations to be seen over the PDF.

Converting the PDF into a raster image with the level of zoom detail that I need would create a file that is too large.

The WebBrowser control doesn't allow the pages to be changed or zoomed programmatically. I also can't remove the Adobe toolbars.

Any third-party libraries I used would need to be free (as in beer).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寂寞花火° 2025-01-10 18:37:30

前提是您的计算机上有一些适用于 IE 的 PDF 查看器插件(例如 Acrobat Reader)...

    <Grid>
            <WebBrowser x:Name="WebBrowser1"
                        Source="C:\Temp\Test.pdf"/>
    </Grid>

工作得很好...

Provided that you have some PDF viewer plugin (such as Acrobat Reader) for IE on your machine...

    <Grid>
            <WebBrowser x:Name="WebBrowser1"
                        Source="C:\Temp\Test.pdf"/>
    </Grid>

works just fine...

因为看清所以看轻 2025-01-10 18:37:30

不幸的是,我还没有足够的声誉来发表评论,所以我将其作为答案。
我最近在 Flash 方面遇到了非常类似的问题,最终我使用了 WindowsFormsHost 和 Overlays /装饰者。只是我的2分钱。

下面是 XAML 创建一个覆盖层作为弹出窗口:

    <Grid>
       <Canvas >
        <WebBrowser  x:Name="wbMain" Width="800" Height="500"></WebBrowser>
        <Popup x:Name="puOverlay" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=wbMain}">
                <Ellipse Canvas.Left="0" Canvas.Top="0" Height="50" Name="headEllipse" Stroke="Black" Fill="Orange" Width="50" Canvas.ZIndex="5"/>
        </Popup>
        <Ellipse Canvas.Left="0" Canvas.Top="0" Height="50" Name="headEllipse1" Stroke="Black" Fill="Orange" Width="50" Canvas.ZIndex="5"/>
         </Canvas>
    </Grid>

为了简单起见,我将覆盖层缩小为一个椭圆形。 Web 浏览器托管在 WindowsFormsHost 中。
这是放置并显示它的代码:

    public MainWindow()
    {
        InitializeComponent();
        puOverlay.VerticalOffset = -60;
        puOverlay.HorizontalOffset = (wbMain.ActualWidth / 2) - 20;
        puOverlay.IsOpen = true;
        ...
    }

非常简单,但是如果仍有不清楚的地方,请随时询问。

Unfortunately I don't have enough reputations yet to make a comment, so I will put it as an answer.
I have had a very similar problem with Flash recently and I ended up using WindowsFormsHost and Overlays/Adorners. Just my 2cents.

Here is XAML creating an overlay as a popup window:

    <Grid>
       <Canvas >
        <WebBrowser  x:Name="wbMain" Width="800" Height="500"></WebBrowser>
        <Popup x:Name="puOverlay" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=wbMain}">
                <Ellipse Canvas.Left="0" Canvas.Top="0" Height="50" Name="headEllipse" Stroke="Black" Fill="Orange" Width="50" Canvas.ZIndex="5"/>
        </Popup>
        <Ellipse Canvas.Left="0" Canvas.Top="0" Height="50" Name="headEllipse1" Stroke="Black" Fill="Orange" Width="50" Canvas.ZIndex="5"/>
         </Canvas>
    </Grid>

For the simplicity sake I reduced my overlay to one ellipse. Web Browser is hosted in WindowsFormsHost.
Here is the code placing and showing it:

    public MainWindow()
    {
        InitializeComponent();
        puOverlay.VerticalOffset = -60;
        puOverlay.HorizontalOffset = (wbMain.ActualWidth / 2) - 20;
        puOverlay.IsOpen = true;
        ...
    }

Pretty simple, however don't hesitate to ask if something is still unclear.

虫児飞 2025-01-10 18:37:30

我还没有找到任何运行良好的免版税第三方 WPF 控件。 Telerik 有一个 pdf 查看器,但它不能处理所有类型,也不能很好地处理大型文档。我也尝试过 Syncfusion,但也有问题。我最终将 WindowsFormsHost 与另一个第 3 方 GD 图片的 Windows 窗体查看器一起使用。不过他们说他们正在制作 WPF 版本。

现在还有其他的,你必须为每一个可能很好的服务器安装付费,但我只是无法使用它。

I haven't found any good royalty free 3rd party WPF controls that work well. Telerik has a pdf viewer, but it doesn't do all types and won't do large documents well for me. I tried Syncfusion's as well and that was buggy too. I ended up using WindowsFormsHost with a another 3rd party GD picture's windows forms viewer. They say they're making a WPF version though.

Now there are others that you have to pay for every server install that might be good, I just can't work with that though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文