c#添加PDF注释(5种类型)

  

【前言】

  

向文档添加注释,是一种比较常用的向读者传递某些重要信息的手段。通过编程的方式来添加PDF注释,我们可以自定义注释的外观,类型及其他一些个性化的设置,这种可供选择的操作在编程中提供了更多的实用性,因此,本篇文章将介绍添加几种不同类型的PDF注释的方法。下面的示例中,借助控件总结了一些不同类型的注释的具体操作,主要包含以下几种

  
      <李>添加弹出式注释(弹出注释)   <李>添加自由文本注释(自由文本注释)   <李>添加链接式注释(链接注释)   <李>添加多边形注释(多边形注释)   <李>添加线性注释(注释行)   
  <人力资源/>   

【工具使用】

  
      <李>尖顶。李PDF为。net 4.0   
  <人力资源/>   

【代码操作】

  

1。弹出式注释(弹出注释)

  c#

<强>

  使用Spire.Pdf
 <代码>;
  使用Spire.Pdf.General.Find;
  使用System.Drawing;
  使用Spire.Pdf.Annotations;
  使用Spire.Pdf.Graphics;
  
  名称空间Annotation_PDF
  {
  类项目
  {
  静态void Main (string [] args)
  {//初始化PdfDocument类实例,并加载测试文档
  PdfDocument doc=new PdfDocument ();
  doc.LoadFromFile (“sample.pdf”);//获取第一页
  PdfPageBase页面=doc.Pages [0];//调用方法FindText()查找需要添加注释的字符串
  PdfTextFind[]结果=page.FindText (IPCC);;//指定注释添加的位置
  x=结果[0].Position浮动。X - doc.PageSettings.Margins.Top;
  [0].Position浮动y=结果。Y - doc.PageSettings.Margins。左+ [0].Size结果。高度- 23;//创建弹出式注释
  RectangleF矩形=new RectangleF (x, y, 10,0);
  PdfPopupAnnotation popupAnnotation=new PdfPopupAnnotation(矩形);//添加注释内容,并设置注释的图标类型和颜色
  popupAnnotation。文本="联合国政府间气候变化专门委员会,这是一个科学和政府间组织的支持下,联合国。”;
  popupAnnotation。图标=PdfPopupIcon.Help;
  popupAnnotation。颜色=Color.DarkOliveGreen;//添加注释到文件
  page.AnnotationsWidget.Add (popupAnnotation);//保存并打开文档
  doc.SaveToFile (“Annotation.pdf”);
  System.Diagnostics.Process.Start (“Annotation.pdf”);
  }
  }
  }
   
  

在选择注释标签类型时,有以下几种类型可供选择
 C #添加PDF注释(5种类型)
注释添加效果:
 C #添加PDF注释(5种类型)

  

2。自由文本注释(自由文本注释)

  c#

  使用Spire.Pdf
 <代码>;
  使用Spire.Pdf.Annotations;
  使用Spire.Pdf.Graphics;
  使用System.Drawing;
  
  名称空间FreeTextAnnotation_pdf
  {
  类项目
  {
  静态void Main (string [] args)
  {//创建PdfDocument类对象,加载测试文档
  PdfDocument doc=new PdfDocument ();
  doc.LoadFromFile (“sample.pdf”);
  
  PdfPageBase页面=doc.Pages [0];//初始化RectangleF类,指定注释添加的位置,注释图标大小
  RectangleF矩形=new RectangleF (50、500、100、40);
  PdfFreeTextAnnotation textAnnotation=new PdfFreeTextAnnotation(矩形);//添加注释内容
  textAnnotation。文本="这只是一个示例,请参阅原文看到更多!”;//设置注释属性,包括字体,字号,注释边框粗细,边框颜色,填充颜色等=new PdfFont (PdfFontFamily PdfFont字体。TimesRoman 9);
  PdfAnnotationBorder边界=new PdfAnnotationBorder(0.75度);
  textAnnotation。字体=字体;
  textAnnotation。边境=边界;
  textAnnotation。BorderColor=Color.White;
  textAnnotation。LineEndingStyle=PdfLineEndingStyle.Circle;
  textAnnotation。颜色=Color.Transparent;
  textAnnotation。不透明度=0.8度;//添加注释到页面
  page.AnnotationsWidget.Add (textAnnotation);//保存并打开文档
  doc.SaveToFile (“FreeTextAnnotation。pdf”, FileFormat.PDF);
  System.Diagnostics.Process.Start (“FreeTextAnnotation.pdf”);
  }
  }
  }
   
  

添加效果
 C #添加PDF注释(5种类型)

  

3。链接式注释(链接注释)

  c#

  使用Spire.Pdf
 <代码>;
  使用Spire.Pdf.Annotations;
  使用Spire.Pdf.Graphics;
  使用System.Drawing;
  
  名称空间FreeTextAnnotation_pdf
  {
  类项目
  {
  静态void Main (string [] args)
  {//创建PdfDocument类对象,加载测试文档
  PdfDocument doc=new PdfDocument ();
  doc.LoadFromFile (“sample.pdf”);
  
  PdfPageBase页面=doc.Pages [0];//初始化RectangleF类,指定注释添加的位置,注释图标大小
  RectangleF矩形=new RectangleF (50、500、100、40);
  PdfFreeTextAnnotation textAnnotation=new PdfFreeTextAnnotation(矩形);//添加注释内容
  textAnnotation。文本="这只是一个样本,点击这里阅读原始文件!”;//设置注释属性,包括字体,字号,注释边框粗细,边框颜色,填充颜色等=new PdfFont (PdfFontFamily PdfFont字体。TimesRoman 9);
  PdfAnnotationBorder边界=new PdfAnnotationBorder(0.75度);
  textAnnotation。字体=字体;
  textAnnotation。边境=边界;
  textAnnotation。BorderColor=Color.White;
  textAnnotation。LineEndingStyle=PdfLineEndingStyle.Circle;
  textAnnotation。颜色=Color.Transparent;//添加需要链接到的文件地址,并添加链接到注释
  字符串filePath=@ " C: \ \用户管理员桌面\ \ original.pdf”;
  PdfFileLinkAnnotation链接=new PdfFileLinkAnnotation(矩形、filePath);
  page.AnnotationsWidget.Add(链接);//添加注释到页面
  page.AnnotationsWidget.Add (textAnnotation);//保存并打开文档
  doc.SaveToFile (“LinkAnnotation。pdf”, FileFormat.PDF);
  System.Diagnostics.Process.Start (“LinkAnnotation.pdf”);
  }
  }
  }
  

c#添加PDF注释(5种类型)