winform 实现pdf浏览

1.开发工具:VS2013

2.开发环境:win 10 64位

3.添加控件:

打开VS,点击工具箱--常规--右键--“选择项”---“Com组件”,选择Adobe PDF Reader控件(在这之前,需要电脑本机装PDF才会有此com控件)

4.拖动Adobe PDF Reader到form1控件中

5.在form1加载时,写入以下代码:

private void Form1_Load(object sender, EventArgs e)
{
string fileName = MyOpenFileDialog();
axAcroPDF1.LoadFile(fileName);

}

string MyOpenFileDialog()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "PDF文档(*.pdf)|*.pdf";

if (ofd.ShowDialog() == DialogResult.OK)
{
return ofd.FileName;
}
else
{
return null;
}
}

6.运行,出现以下错误:

“System.Runtime.InteropServices.COMException”类型的未经处理的异常在 System.Windows.Forms.dll 中发生

7.选中工程,点击右键--属性--生成--目标平台改为x86

8.再次运行,成功

原文地址:https://www.cnblogs.com/flyrain/p/winform_pdf1.html