c#pdf查看器
FreeSpire.PDF for .NETis aCommunity Editionof theSpire.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-iceblueSpire.PdfViewer-FEBin下的相應版本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
總結
- 上一篇: NgRx Store createSel
- 下一篇: 云顶之弈大元素使拉克丝图鉴 S2全英雄技