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; us

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);
            }
        }
    }
}


 

目录
相关文章
|
7月前
|
开发框架 前端开发 JavaScript
在Winform分页控件中集成导出PDF文档的功能
在Winform分页控件中集成导出PDF文档的功能
|
8月前
|
开发框架 前端开发 JavaScript
在Winform程序中使用Spire.Pdf实现页面添加印章处理
在Winform程序中使用Spire.Pdf实现页面添加印章处理
|
Windows
PDF工具Adobe Arcrobat Pro DC下载安装教程
Acrobat是一款PDF(Portable Document Format,便携式文档格式)编辑软件。借助它,您可以以PDF格式制作和保存你的文档 ,以便于浏览和打印,或使用更高级的功能。
800 0
|
安全 Windows
Adobe 和微软通过微软边缘为 1 亿 Windows 用户带来行业领先的 Acrobat PDF 体验
Adobe 和微软通过微软边缘为 1 亿 Windows 用户带来行业领先的 Acrobat PDF 体验。
Adobe 和微软通过微软边缘为 1 亿 Windows 用户带来行业领先的 Acrobat PDF 体验
|
安全 数据安全/隐私保护
Adobe Acrobat最强PDF编辑器软件下载安装教程步骤指南——全版本
Adobe Acrobat最强PDF编辑器软件下载安装教程步骤指南——全版本
336 0
|
安全 数据安全/隐私保护
Adobe Acrobat最强PDF编辑软件安装下载教程全版本获取安装包
Adobe Acrobat最强PDF编辑软件安装下载教程全版本获取安装包
361 0
|
数据处理 数据格式
Adobe Acrobat PDF编辑器,具备创建阅读编辑合并PDF的功能
Adobe Acrobat PDF编辑器,具备创建阅读编辑合并PDF的功能
206 0
|
安全 数据安全/隐私保护 Windows
Adobe Acrobat 最厉害的PDF编辑器软件下载安装教程全版本获取
Adobe Acrobat 最厉害的PDF编辑器软件下载安装教程全版本获取
265 0
|
安全 JavaScript 前端开发
Adobe Acrobat DC最新版本的PDF编辑器软件安装教程安装包
Adobe Acrobat DC最新版本的PDF编辑器软件安装教程安装包
308 0
PDF - 使用 Adobe Acrobat 压缩 PDF 大小
PDF - 使用 Adobe Acrobat 压缩 PDF 大小
538 0
PDF - 使用 Adobe Acrobat 压缩 PDF 大小

热门文章

最新文章