標籤:
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
c#pdf查看器