使用C#在Windows窗体中查看PDF [英] Viewing PDF in Windows forms using C#

查看:829
本文介绍了使用C#在Windows窗体中查看PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在一个WinForms工具来查看PDF文件?我见过的解决方案,比如在图片框的PDF文件转换成图像,并显示它们。但是,我问我是否可以查看文件为PDF。有从Adobe或Microsoft支持此任何工具?

Is there any way to view PDF files in a Winforms tool? I've seen solutions such as converting the pdf file into images and showing them in an picture box. However, I am asking whether i can view the file as PDF. Is there any tool from adobe or from Microsoft that supports this?

推荐答案

您可以通过以下方式使用 System.Diagnostics.Process.Start 以及 WIN32 ShellExecute函数互操作,使用默认浏览器打开PDF文件:

you can use System.Diagnostics.Process.Start as well as WIN32 ShellExecute function by means of interop, for opening PDF files using the default viewer:

System.Diagnostics.Process.Start("SOMEAPP.EXE","Path/SomeFile.Ext");

[System.Runtime.InteropServices.DllImport("shell32. dll")]
private static extern long ShellExecute(Int32 hWnd, string lpOperation, 
                                    string lpFile, string lpParameters, 
                                        string lpDirectory, long nShowCmd);

另一种方法是将一个 WebBrowser控件插入到表单中,然后使用的导航的用于打开PDF文件的方法:

Another approach is to place a WebBrowser Control into your Form and then use the Navigate method for opening the PDF file:

ThewebBrowserControl.Navigate(@"c:\the_file.pdf");

这篇关于使用C#在Windows窗体中查看PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆