c#pdf查看器

时间:2024-01-18 13:05:02

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

c#pdf查看器

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

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

c#pdf查看器

将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, );
this.m_isAttachmentAnnotation = true;
this.listView1.Visible = true;
this.listView1.Items.Clear();
this.listView1.Columns.Clear();
if (this.pdfDocumentViewer1.IsDocumentLoaded && this.pdfDocumentViewer1.PageCount > )
{
this.listView1.View = View.Details;
this.listView1.Columns.Add("注解",);
this.listView1.Columns.Add("内容",);
this.listView1.Columns.Add("页码",);
this.listView1.Columns.Add("位置",);
//获取pdf注解列表
PdfDocumentAttachmentAnnotation[] annotations = this.pdfDocumentViewer1.GetAttachmentAnnotaions();
if (annotations != null && annotations.Length > )
{
//注解属性
for (int i = ; 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[].Tag;
this.pdfDocumentViewer1.GotoAttachmentAnnotation(annotation);
}
}

最后的效果:

c#pdf查看器

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

某pdf软件加载某文档

c#pdf查看器

Spire.PdfViewer加载的某文档

c#pdf查看器

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