HTML JPG PDF XML DOCX
  Product Family
PDF

通过 .NET SDK 向 PDF 添加高亮文本注释

用于通过 .NET 向 PDF 文档添加注释的 API。

Get Started

如何使用 Cloud .NET SDK 向 PDF 文档添加注释

为了通过 Cloud .NET SDK 向 PDF 文档添加注释,我们将使用 Aspose.PDF Cloud .NET SDK 此 Cloud SDK 允许您轻松构建基于云的 PDF 创建、编辑和转换应用程序,适用于 C#、ASP.NET 或其他 .NET 语言的各种云平台。打开 NuGet 包管理器,搜索 Aspose.PDF Cloud 并安装。您也可以使用以下命令从包管理器控制台安装。

包管理器控制台命令


    PM> Install-Package Aspose.Pdf-Cloud
     

使用 .NET SDK 添加注释的步骤

Aspose.PDF Cloud 开发人员可以轻松地加载和附加注释到 PDF 文档,仅需几行代码。

  1. 将 PDF 上传到云存储。
  2. 创建一个新的高亮注释,定义位置、颜色、文本和样式。
  3. 使用 Aspose Cloud API 将注释发送到指定页面。
  4. 检查响应并记录结果。
  5. 下载更新后的文件以供本地使用。
 

此示例代码展示了如何向 PDF 文档添加注释


    using Aspose.Pdf.Cloud.Sdk.Model;

    namespace Annotations
    {
        public class NewHighlightAnnotation
        {
            public static async Task Append(AnnotationsHelper helper, string documentName, int pageNumber, string outputName, string remoteFolder)
            {
                await helper.UploadFile(documentName);

                List<HighlightAnnotation> annotations = new List<HighlightAnnotation>
                {
                    new HighlightAnnotation(
                        Name: "Highlight_NEW_Annotation",
                        Rect: new Rectangle(100,350, 450,400),
                        Flags: new List<AnnotationFlags>() { AnnotationFlags.Default },
                        HorizontalAlignment: HorizontalAlignment.Left,
                        VerticalAlignment: VerticalAlignment.Top,
                        RichText: helper.config.NEW_HL_ANNOTATION_TEXT,
                        Subject: helper.config.NEW_HL_ANNOTATION_SUBJECT,
                        Contents: helper.config.NEW_HL_ANNOTATION_CONTENTS,
                        Title: helper.config.NEW_HL_ANNOTATION_DESCRIPTION,
                        ZIndex: 1,
                        Color: new Color(A: 0xFF, R: 0x00, G: 0xFF, B: 0x00),
                        QuadPoints: new List<Point>() {
                            new Point(X: 10, Y: 10),
                            new Point(X: 20, Y: 10),
                            new Point(X: 10, Y: 20),
                            new Point(X: 10, Y: 10)
                        },
                        Modified: "03/27/2025 00:00:00.000 AM"
                    )
                };
                AsposeResponse response = await helper.pdfApi.PostPageHighlightAnnotationsAsync(documentName, pageNumber, annotations, folder: remoteFolder);

                if (response == null)
                    Console.WriteLine("NewHighlightAnnotation(): Unexpected error!");
                else if (response.Code < 200 || response.Code > 299)
                    Console.WriteLine("NewHighlightAnnotation(): Failed to append highlight annotation to the document.");
                else
                {
                    Console.WriteLine("NewHighlightAnnotation(): annotations '{0}' added to the document '{1}.", helper.config.NEW_HL_ANNOTATION_TEXT, documentName);
                    await helper.DownloadFile(documentName, outputName, "add_highlight_annotation_");
                }
            }
        }
    }