且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用C#在Windows窗体中查看PDF

更新时间:2023-02-12 21:46:54

您可以通过以下方式使用 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");