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


 

目录
相关文章
|
2月前
|
应用服务中间件
使用 Adobe Livecycle Enterprise service 将 word 文档转换成 PDF 格式
使用 Adobe Livecycle Enterprise service 将 word 文档转换成 PDF 格式
28 0
|
6月前
|
存储 XML BI
如何把 SAP ABAP 系统里一张数据库表的内容,显示在 Adobe PDF Form 里试读版
如何把 SAP ABAP 系统里一张数据库表的内容,显示在 Adobe PDF Form 里试读版
63 0
|
6月前
|
XML 存储 Java
使用 ABAP 调用 Adobe Document Service 生成 PDF 文档
使用 ABAP 调用 Adobe Document Service 生成 PDF 文档
55 0
|
11月前
|
Windows
PDF工具Adobe Arcrobat Pro DC下载安装教程
Acrobat是一款PDF(Portable Document Format,便携式文档格式)编辑软件。借助它,您可以以PDF格式制作和保存你的文档 ,以便于浏览和打印,或使用更高级的功能。
598 0
|
安全 Windows
Adobe 和微软通过微软边缘为 1 亿 Windows 用户带来行业领先的 Acrobat PDF 体验
Adobe 和微软通过微软边缘为 1 亿 Windows 用户带来行业领先的 Acrobat PDF 体验。
Adobe 和微软通过微软边缘为 1 亿 Windows 用户带来行业领先的 Acrobat PDF 体验
PDF - 使用 Adobe Acrobat 压缩 PDF 大小
PDF - 使用 Adobe Acrobat 压缩 PDF 大小
368 0
PDF - 使用 Adobe Acrobat 压缩 PDF 大小
|
Unix Linux iOS开发
卸载Adobe Reader!一款免费、好用、轻量的PDF阅读器
一直以来,有不少同学问过我“有没有比较好用的PDF阅读器?”
卸载Adobe Reader!一款免费、好用、轻量的PDF阅读器
|
算法 安全 编译器
PDF之父、Adobe联合创始人离世,乔布斯收购未果给了他第一桶金
Adobe的传奇创始人离世,对艺术世界影响巨大的开发者,pdf、photoshop都是他的成名作。
225 0
PDF之父、Adobe联合创始人离世,乔布斯收购未果给了他第一桶金
|
机器学习/深度学习 人工智能 算法
手机看PDF有救了!Adobe发布「Liquid Mode」液体模式自适应手机屏幕
Adobe近日在手机应用程序Acrobat Reader中发布了一个叫做「Liquid Mode」液体模式的功能,可以根据智能手机的屏幕大小来自适应调节PDF的排版,获得更好的效果。
751 0
手机看PDF有救了!Adobe发布「Liquid Mode」液体模式自适应手机屏幕
使用Adobe Lifecycle ES将若干个word合并成一个PDF
使用Adobe Lifecycle ES将若干个word合并成一个PDF
使用Adobe Lifecycle ES将若干个word合并成一个PDF