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.再次运行,成功

相关文章:

  • 2021-12-09
  • 2021-11-08
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
猜你喜欢
  • 2021-12-19
  • 2021-12-05
  • 2021-12-05
  • 2021-04-07
相关资源
相似解决方案