利用Adobe PDF Reader 控件,實現在Winform中預覽PDF文檔。 實現方法如下:
(1)前提條件
必須事先在計算機安裝Adobe Reader軟件。Adobe Reader是免費軟件,可以從Adobe官網下載安裝
(2)在Visual Studio中新建壹個“Windows 窗體應用程序”項目
(3)在工具箱上點鼠標右鍵-->選擇項 -->COM組件-->Adobe PDF Reader
(4)在窗體Form1上布置壹個Adobe PDF Reader控件和壹個Button控件
(5)Form1窗體代碼Form1.cs
using?System;using?System.Windows.Forms;
using?System.IO;
namespace?WindowsFormsApplication1
{
public?partial?class?Form1?:?Form
{
public?Form1()
{
InitializeComponent();
button1.Text?=?"打開PDF文檔...";
}
private?void?button1_Click(object?sender,?EventArgs?e)
{
//?利用OpenDialog對話框,選擇要顯示的PDF文檔
OpenFileDialog?openDlg?=?new?OpenFileDialog();
openDlg.Filter?=?"PDF文檔|*.pdf";
if?(openDlg.ShowDialog()?==?DialogResult.OK)
{
//?在Adobe?PDF?Reader中顯示PDF文檔
axAcroPDF1.LoadFile(openDlg.FileName);
}
}
}
}
(6)運行效果
程序啟動
點擊“打開PDF文檔...”按鈕,顯示對話框
打開並顯示PDF文檔