Csharp: winform PDF view control use Adobe Reader X

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AcroPDFLib;//引用COM組件Adobe Acrobat Browser Control Type Library 1.0 //http://www.adobe.com/devnet/acrobat/sdk/eula.html
using System.Runtime.InteropServices;

namespace WindowsChineseCalender
{
    /// <summary>
    ///安裝 Adobe Reader X
    /// winform pdf view control
    /// Geovin Du 塗聚文
    /// 20121022 
    /// </summary>
    public partial class PDFviewControlForm : Form
    {

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern uint GetShortPathName(
           [MarshalAs(UnmanagedType.LPTStr)] string lpszLongPath,
           [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpszShortPath,
           uint cchBuffer);

        /// <summary>
        /// 
        /// </summary>
        public PDFviewControlForm()
        {
            InitializeComponent();
            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";
           
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PDFviewControlForm_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 瀏覽本地文件
        /// 塗聚文
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void browseButtonLeft_Click(object sender, EventArgs e)
        {
       
            OpenFileDialog openFile = new OpenFileDialog();
            DialogResult result = openFile.ShowDialog();

    
            if (result == DialogResult.Cancel)
                return;

          
            string strFileName = openFile.FileName;

       
            string strFileNameDup = strFileName;
            if (strFileNameDup.ToUpper().EndsWith(".PDF"))
            {
                addressLeft.Text = strFileName;
            }
            else
                MessageBox.Show(this, "請選擇PDF文件!", "文件類型錯誤", MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 
        }
        /// <summary>
        /// 打開文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void goButtonLeft_Click(object sender, EventArgs e)
        {
            if (0 == addressLeft.Text.Length)
                MessageBox.Show(this, "輸入正解的 \"地址\"比 !", "錯誤提示",
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            if (addressLeft.Text.StartsWith("http://"))
                pdfWindowLeft.src = addressLeft.Text; //網絡文件地址
            else
            {
                //本地文件
                StringBuilder shortFileName = new StringBuilder(4096);
                uint shortFileNameSize = (uint)shortFileName.Capacity;
                if (GetShortPathName(addressLeft.Text, shortFileName, shortFileNameSize) != 0)
                    pdfWindowLeft.LoadFile(shortFileName.ToString());
                else
                    MessageBox.Show(this, "不正確的文件.", "需正確的文件",
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
        }
    }
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值