使用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文档添加注释的示例代码分享(图)的详细内容!

返回前面的内容

相关阅读 >>

C# socket实现简单控制台案例

详解C#winform循环播放多个视频的代码示例

C#开发 winform如何在选项卡中集成加载多个窗体 实现窗体复用详解(图)

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

讲解什么是msmq

详解C#把datatable中数据一次插入数据库的示例代码

具体介绍C#将指定网页添加到收藏夹的方法

C#高级编程(二)-核心C#的详解

C#中实现退出程序后自动重新启动程序的示例代码分享

C#开发实例-订制屏幕截图工具(五)针对拖拽时闪烁卡顿的优化

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




打赏

取消

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

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

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

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

评论

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