zoukankan      html  css  js  c++  java
  • Csharp: winform PDF view control use Adobe Reader X

      1 using System;
      2 using System.Collections.Generic;
      3 using System.ComponentModel;
      4 using System.Data;
      5 using System.Drawing;
      6 using System.Linq;
      7 using System.Text;
      8 using System.Windows.Forms;
      9 using AcroPDFLib;//引用COM組件Adobe Acrobat Browser Control Type Library 1.0 //http://www.adobe.com/devnet/acrobat/sdk/eula.html
     10 using System.Runtime.InteropServices;
     11 
     12 namespace WindowsChineseCalender
     13 {
     14     /// <summary>
     15     ///安裝 Adobe Reader X
     16     /// winform pdf view control
     17     /// Geovin Du 塗聚文
     18     /// 20121022 
     19     /// </summary>
     20     public partial class PDFviewControlForm : Form
     21     {
     22 
     23         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
     24         static extern uint GetShortPathName(
     25            [MarshalAs(UnmanagedType.LPTStr)] string lpszLongPath,
     26            [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpszShortPath,
     27            uint cchBuffer);
     28 
     29         /// <summary>
     30         /// 
     31         /// </summary>
     32         public PDFviewControlForm()
     33         {
     34             InitializeComponent();
     35             this.addressLeft.Text = "http://www.dusystem.com/%E4%BD%8F%E6%88%BF%E5%92%8C%E5%9F%8E%E4%B9%A1%E5%BB%BA%E8%AE%BE%E9%83%A8%E7%9D%A3%E5%AF%9F%E5%8A%9E%E5%85%AC%E5%AE%A4201200825.pdf";
     36            
     37         }
     38         /// <summary>
     39         /// 
     40         /// </summary>
     41         /// <param name="sender"></param>
     42         /// <param name="e"></param>
     43         private void PDFviewControlForm_Load(object sender, EventArgs e)
     44         {
     45 
     46         }
     47         /// <summary>
     48         /// 瀏覽本地文件
     49         /// 塗聚文
     50         /// </summary>
     51         /// <param name="sender"></param>
     52         /// <param name="e"></param>
     53         private void browseButtonLeft_Click(object sender, EventArgs e)
     54         {
     55        
     56             OpenFileDialog openFile = new OpenFileDialog();
     57             DialogResult result = openFile.ShowDialog();
     58 
     59     
     60             if (result == DialogResult.Cancel)
     61                 return;
     62 
     63           
     64             string strFileName = openFile.FileName;
     65 
     66        
     67             string strFileNameDup = strFileName;
     68             if (strFileNameDup.ToUpper().EndsWith(".PDF"))
     69             {
     70                 addressLeft.Text = strFileName;
     71             }
     72             else
     73                 MessageBox.Show(this, "請選擇PDF文件!", "文件類型錯誤", MessageBoxButtons.OK,
     74                     MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 
     75         }
     76         /// <summary>
     77         /// 打開文件
     78         /// </summary>
     79         /// <param name="sender"></param>
     80         /// <param name="e"></param>
     81         private void goButtonLeft_Click(object sender, EventArgs e)
     82         {
     83             if (0 == addressLeft.Text.Length)
     84                 MessageBox.Show(this, "輸入正解的 \"地址\"比 !", "錯誤提示",
     85                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
     86             if (addressLeft.Text.StartsWith("http://"))
     87                 pdfWindowLeft.src = addressLeft.Text; //網絡文件地址
     88             else
     89             {
     90                 //本地文件
     91                 StringBuilder shortFileName = new StringBuilder(4096);
     92                 uint shortFileNameSize = (uint)shortFileName.Capacity;
     93                 if (GetShortPathName(addressLeft.Text, shortFileName, shortFileNameSize) != 0)
     94                     pdfWindowLeft.LoadFile(shortFileName.ToString());
     95                 else
     96                     MessageBox.Show(this, "不正確的文件.", "需正確的文件",
     97                         MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
     98             }
     99         }
    100     }
    101 }
    哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)成功.---Geovin Du(涂聚文)
  • 相关阅读:
    Metropolis(大都会):以太坊网络的下一个阶段
    《区块链开发技术综述》乱弹
    Ext.Net学习笔记09:Ext.Net Store的用法
    Ext.Net学习笔记09:Ext.Net Store的用法
    Spring整合redis配置文件详解
    Spring整合redis配置文件详解
    Spring整合redis配置文件详解
    Spring整合redis配置文件详解
    Android环境配置----在Ubuntu上安装JDK
    Android环境配置----在Ubuntu上安装JDK
  • 原文地址:https://www.cnblogs.com/geovindu/p/2735880.html
Copyright © 2011-2022 走看看