C#如何给PDF文档添加注释
2017-11-21 00:00
531 查看
摘要: PDF类型的文档是比较常用的一种的文本格式,应用广泛。在做文档时,可以对文档添加注释来阐明文档中某些内容的意义,或者向读者传达必要的信息。在对PDF添加注释的方法中,可以通过C#代码语言来添加。这里提供了一个添加注释的方法。
使用C#语言添加PDF注释当中,需要使用到Spire.PDF for .NET。可以在官网上下载免费版(https://www.e-iceblue.cn/Downloads/Free-Spire-PDF-NET.html)。
注意,需要添加dll文件到程序中,并且也要添加using 指令
1.给文本添加注释
主要代码如下:
效果示例:
2.添加自由文本注释
效果示例:
本文为转载文章,详细信息可以查看原文。
使用C#语言添加PDF注释当中,需要使用到Spire.PDF for .NET。可以在官网上下载免费版(https://www.e-iceblue.cn/Downloads/Free-Spire-PDF-NET.html)。
注意,需要添加dll文件到程序中,并且也要添加using 指令
1.给文本添加注释
主要代码如下:
PdfDocument doc = new PdfDocument(); PdfPageBase page = doc.Pages.Add(); PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 13); string text = "HelloWorld"; PointF point = new PointF(200, 100); page.Canvas.DrawString(text, font, PdfBrushes.Red, point); PdfTextMarkupAnnotation annotation1 = new PdfTextMarkupAnnotation("管理员", "一般来说,这是每一种计算机编程语言中最基本、最简单的程序", text, new PointF(0, 0), font); annotation1.Border = new PdfAnnotationBorder(0.75f); annotation1.TextMarkupColor = Color.Green; annotation1.Location = new PointF(point.X + doc.PageSettings.Margins.Left, point.Y + doc.PageSettings.Margins.Left); (page as PdfNewPage).Annotations.Add(annotation1); doc.SaveToFile("result.pdf");
效果示例:
2.添加自由文本注释
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# 如何给现有/新建PDF文档添加注释或标注
- 使用C#给PDF文档添加注释的实现代码
- 如何在使用itext生成pdf文档时给文档添加背景图片
- 在PDF文档中添加附件需要我们如何去进行操作
- 开发人员在使用Aspose.Pdf for .NET时如何用C#和VB两种代码添加附件到PDF文档?
- 如何给word文档添加注释
- 如何在使用itext生成pdf文档时给文档添加背景图片
- C# 如何在PDF文档中添加一维条形码和二维条形码
- 利用C#如何给PDF文档添加文本与图片页眉
- pdf文档如何编辑添加图章
- PDF文档如何添加图片签名
- 如何在ABBYY PDF Transformer+中将文本添加到PDF文档
- 如何使用ABBYY FineReader 14添加文本到PDF文档
- PDF文档如何添加图片签名
- PDF文档如何添加、删除或移动页面
- 如何在博客/网页中添加pdf文档
- power designer中如何给导出的xml文档添加注释功能
- C# 如何在PDF文档中添加打印按钮
- 如何在单文档工程中对对话框添加OnInitDialog函数