博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# WinForm 打開PDF文檔
阅读量:4042 次
发布时间:2019-05-24

本文共 1858 字,大约阅读时间需要 6 分钟。

               

                                            
方法一:利用Procss.Start(“pdf文档路径”)

     eg:    System.Diagnostics.Process.Start("F:\\1.pdf"); 

方法二:

(1)在工具箱中添加Adobe提供的ActiveX控件,如图所示:

(2)拖动Adobe Acrobat 7.0 Browser Control控件到窗体中,并创建一个button4按钮,并添加按钮事件。

按钮事件代码如下:

方案一:通过查找pdf文档

  private void btn1_Click(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;       

         }       

 

    }

方案二:直接打开pdf文档

   public void MyOpenFileDialog()        {            AxAcroPDFLib.AxAcroPDF axAcroPDF = new AxAcroPDFLib.AxAcroPDF();           // axAcroPDF.BeginInit();            ((System.ComponentModel.ISupportInitialize)(axAcroPDF)).BeginInit();            axAcroPDF.Location = new System.Drawing.Point(0, 24);           // axAcroPDF.Size = new System.Drawing.Size(292,242);                   axAcroPDF.Dock = DockStyle.Fill;                      this.Controls.Add(axAcroPDF);            //axAcroPDF.EndInit();            ((System.ComponentModel.ISupportInitialize)(axAcroPDF)).EndInit();            string filename = MyLoadFile();                axAcroPDF.LoadFile( Application.StartupPath+"\\Instruction Manual-EN.pdf");            axAcroPDF.setView("fit");                      axAcroPDF.setShowScrollbars(true);            axAcroPDF.setShowToolbar(true);        }   

  private void btn1_Click(object sender, EventArgs e)     

   {            

    string filename = MyOpenFileDialog();

           axAcroPDF1.LoadFile(filename); 

     }

方案二可能出现的异常:

System.Windows.Forms.AxHost+InvalidActiveXStateException

其解决的办法:

 

      

 出现题目的异常,多是引用第三方控件引起的,因此在NEW时,需要初始化该对象:

   

         AxESACTIVEXLib.AxESActiveX ax = new AxESACTIVEXLib.AxESActiveX();

            ((System.ComponentModel.ISupportInitialize)(this.ax)).BeginInit();或者 axAcroPDF.BeginInit();
             this.Controls.Add(ax);
            ((System.ComponentModel.ISupportInitialize)(this.ax)).EndInit();或者axAcroPDF.EndInit();
————————————————
版权声明:本文为CSDN博主「已被格式化的叔叔」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sl1990129/article/details/78094602

你可能感兴趣的文章
AsyncTask、View.post(Runnable)、ViewTreeObserver三种方式总结frame animation自动启动
查看>>
Android中AsyncTask的简单用法
查看>>
解决跨网场景下,CAS重定向无法登录的问题(无需修改现有代码)
查看>>
java反编译命令
查看>>
activemq依赖包获取
查看>>
概念区别
查看>>
final 的作用
查看>>
在Idea中使用Eclipse编译器
查看>>
idea讲web项目部署到tomcat,热部署
查看>>
IDEA Properties中文unicode转码问题
查看>>
Idea下安装Lombok插件
查看>>
zookeeper
查看>>
Idea导入的工程看不到src等代码
查看>>
技术栈
查看>>
Jenkins中shell-script执行报错sh: line 2: npm: command not found
查看>>
8.X版本的node打包时,gulp命令报错 require.extensions.hasownproperty
查看>>
Jenkins 启动命令
查看>>
Maven项目版本继承 – 我必须指定父版本?
查看>>
通过C++反射实现C++与任意脚本(lua、js等)的交互(二)
查看>>
利用清华镜像站解决pip超时问题
查看>>