划线文本 C#

在文档中应用删除线是一种常见的编辑功能,通常用于修订、校对和协作编辑。这种方法视觉上指示哪些文本需要被删除或替换,同时保持原始内容的可读性。在这篇文章中,我们将介绍如何使用 C# 和 Conholdate.Total for .NET 来添加删除线效果。这个强大的 SDK 使您能够高精度和灵活性地注释文档,是标记 PDF 和其他格式中文本更改的理想解决方案。

为什么在文档中使用删除线?

  • 它帮助审稿人和编辑清晰地沟通内容中应该删除或修订的部分。

  • Keeping the original text visible, even when marked for deletion, improves traceability during content revisions.

  • 删除线注释使得在团队环境中版本控制和文档跟踪变得更加可管理。

  • 法律、学术和商业文件通常需要可见的编辑,以确保合规、透明和准确。

C#中的删除线文本 - SDK安装

您需要安装 Conholdate.Total for .NET 才能在文档中(包括 PDF、DOC、DOCX 等)删除文本。只需在 MS Visual Studio 中运行以下 NuGet 安装命令:

Install-Package Conholdate.Total

使用 C# 添加删除线文本

以下C#代码演示了如何在PDF文档中添加删除线注释。这种方法使用基于坐标的定位来指定文档中应该具有删除线效果的确切区域。

// Initialize the annotator with the input PDF file
GroupDocs.Annotation.Annotator annotator = new GroupDocs.Annotation.Annotator("document.pdf");

// Create a StrikeoutAnnotation object
GroupDocs.Annotation.Models.AnnotationModels.StrikeoutAnnotation strikeout = new GroupDocs.Annotation.Models.AnnotationModels.StrikeoutAnnotation();

// Set color and opacity
strikeout.FontColor = 0xFF0000;
strikeout.Opacity = 0.7;

// Target page number (zero-based index)
strikeout.PageNumber = 0;

// Define the rectangle where the strikethrough will be applied
List<Point> points = new List<Point>();
points.Add(new Point(180, 730));
points.Add(new Point(300, 730));
points.Add(new Point(180, 700));
points.Add(new Point(300, 700));
strikeout.Points = points;

// Add the strikeout annotation to the document
annotator.Add(strikeout);

// Save the modified document
annotator.Save("strikethrough-text.pdf");

此示例将删除线注释配置为红色和部分透明,并将其应用于 PDF 第一页的指定区域。Points 集合定义了删除线将出现的矩形区域。应用注释后,文档将包含视觉编辑的保存。

结论

删除线注释是有效审查和编辑文档的实用且重要的功能。使用 Conholdate.Total for .NET,您可以轻松且精确地在 C# 应用程序中实现此功能。无论您是在开发桌面应用程序、基于 Web 的平台,还是文档工作流程系统,使用删除线注释添加红线功能有助于增强清晰度、改善沟通并简化修订过程。SDK 的灵活性确保您的文档在格式上保持可编辑、协作和视觉一致。

另请参阅