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.html

本篇文章將介紹用e-iceblue插件開發簡單的pdf查看器。app

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工具欄,this

 

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

this.pdfDocumentViewer1.LoadFromFile函數是加載一個pdf文件,參數是文件路徑。.net

this.pdfDocumentViewer1.Print函數是打印當前文檔。插件

下面是獲取註解和轉到註解的代碼code

/// <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

相關文章
相關標籤/搜索