c#pdf查看器

Free Spire.PDF for .NET is a Community Edition of the Spire.PDF for .NET, which is a totally free PDF component for commercial and personal use. As a standalone C#/VB.NET component, Free Spire.PDF for .NET enables developers to create, write, edit, convert, print, handle and read PDF files on any .NET applications.

本篇文章将介绍用e-iceblue插件开发简单的pdf查看器。

e-iceblue提供包括处理office在内的所有插件,地址:http://www.e-iceblue.com/

http://www.e-iceblue.com/Introduce/free-pdf-component.html下载免费版的pdf插件安装完成后,就可以看到下面的demo窗体。该窗体展示了所有操作pdf的样例和代码,你也可以直接运行demo

该pdf插件将处理附件、标注、导出、打开、分页、打印、存储等相关pdf操作。

新建vs2012 winform程序,将C:\Program Files (x86)\e-iceblue\Spire.PdfViewer-FE\Bin下的相应版本dll导入vs2012工具栏,

 

将PfdViewer控件拖至新建窗体上,Spire.PdfViewer的引用就算完成了。

this.pdfDocumentViewer1.LoadFromFile函数是加载一个pdf文件,参数是文件路径。

this.pdfDocumentViewer1.Print函数是打印当前文档。

下面是获取注解和转到注解的代码

/// <summary>
        /// 获取pdf注解
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAttachmentAnnotation_Click(object sender, EventArgs e)
        {
            this.tableLayoutPanel1.SetRowSpan(this.pdfDocumentViewer1, 1);
            this.m_isAttachmentAnnotation = true;
            this.listView1.Visible = true;
            this.listView1.Items.Clear();
            this.listView1.Columns.Clear();
            if (this.pdfDocumentViewer1.IsDocumentLoaded && this.pdfDocumentViewer1.PageCount > 0)
            {
                this.listView1.View = View.Details;
                this.listView1.Columns.Add("注解",200);
                this.listView1.Columns.Add("内容",180);
                this.listView1.Columns.Add("页码",80);
                this.listView1.Columns.Add("位置",160);
                //获取pdf注解列表
                PdfDocumentAttachmentAnnotation[] annotations = this.pdfDocumentViewer1.GetAttachmentAnnotaions();
                if (annotations != null && annotations.Length > 0)
                {
                    //注解属性
                    for (int i = 0; i < annotations.Length; i++)
                    {
                        PdfDocumentAttachmentAnnotation annotation = annotations[i];
                        ListViewItem item = new ListViewItem(annotation.FileName);
                        item.SubItems.Add(annotation.Text);
                        item.SubItems.Add(annotation.PageIndex.ToString());
                        item.SubItems.Add(annotation.Location.ToString());
                        item.Tag = annotation;
                        this.listView1.Items.Add(item);
                    }
                }

            }
        }
        /// <summary>
        /// 转到注解
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listView1_Click(object sender, EventArgs e)
        {
            if (this.m_isAttachmentAnnotation)
            {
                PdfDocumentAttachmentAnnotation annotation = (PdfDocumentAttachmentAnnotation)this.listView1.SelectedItems[0].Tag;
                this.pdfDocumentViewer1.GotoAttachmentAnnotation(annotation);
            }
        }

 

最后的效果:

缺点:经过无数个文档加载测试发现某些pdf文档加载问题,如下

某pdf软件加载某文档

Spire.PdfViewer加载的某文档

源码下载:http://download.csdn.net/detail/oyipiantian/8683459

posted @ 2015-05-10 17:29  波谷  阅读(4665)  评论(0编辑  收藏  举报