使用C#给PDF文档添加注释的示例代码分享(图)


当前第2页 返回上一页

同样,给文档添加自由文本注释也相对简单。

步骤1:新建一个PDF文档对象,并添加一个新页面。

1

2

PdfDocument doc = new PdfDocument();

PdfPageBase page = doc.Pages.Add();

步骤2:初始化一个PdfFreeTextAnnotation,然后自定义注释的文本。

1

2

3

RectangleF rect = new RectangleF(0, 40, 150, 50);

PdfFreeTextAnnotation textAnnotation = new PdfFreeTextAnnotation(rect);

textAnnotation.Text = "Free text annotation ";

步骤3:设置注释的属性,包括字体、填充颜色、边框颜色和透明度。

1

2

3

4

5

6

7

8

PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 10);

PdfAnnotationBorder border = new PdfAnnotationBorder(1f);

textAnnotation.Font = font;

textAnnotation.Border = border;

textAnnotation.BorderColor = Color. Purple;

textAnnotation.LineEndingStyle = PdfLineEndingStyle.Circle;

textAnnotation.Color = Color. Pink;

textAnnotation.Opacity = 0.8f;

步骤4:添加注释到页面。

1

page.AnnotationsWidget.Add(textAnnotation);

步骤5:保存并重新打开文档。

1

2

doc.SaveToFile("FreeTextAnnotation.pdf", FileFormat.PDF);

System.Diagnostics.Process.Start("FreeTextAnnotation.pdf");

这是添加自由文本注释的效果图:

全部代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

PdfDocument doc = new PdfDocument();

      PdfPageBase page = doc.Pages.Add();

       

      RectangleF rect = new RectangleF(0, 40, 150, 50);

      PdfFreeTextAnnotation textAnnotation = new PdfFreeTextAnnotation(rect);

      textAnnotation.Text = "Free text annotation ";

     

      PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 10);

      PdfAnnotationBorder border = new PdfAnnotationBorder(1f);

      textAnnotation.Font = font;

      textAnnotation.Border = border;

      textAnnotation.BorderColor = Color. Purple;

      textAnnotation.LineEndingStyle = PdfLineEndingStyle.Circle;

      textAnnotation.Color = Color.Pink;

      textAnnotation.Opacity = 0.8f;

       

      page.AnnotationsWidget.Add(textAnnotation);

      doc.SaveToFile("FreeTextAnnotation.pdf", FileFormat.PDF);

      System.Diagnostics.Process.Start("FreeTextAnnotation.pdf");

以上就是使用C#给PDF文档添加注释的示例代码分享(图)的详细内容!

返回前面的内容

相关阅读 >>

.net中C#集合的交集、并集、差集

不用ide也能写出C#的hello world详解(图)

使用C#操作windowad之添加对象到用户组

C#获取ip及判断ip是否在区间的示例代码

详细介绍data url生成工具C#版第二版的示例代码

讲解什么是msmq

详细介绍C#该行已经属于另一个表的解决方法

关于C#代码convert.tochar(null);出现异常的详解(图)

C#之解决百度地图api app sn校验失败问题(代码实例)

C#和.net是一个东西吗?C#与.net的区别与联系

更多相关阅读请进入《C#》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...