HTML JPG PDF XML DOCX
  Product Family
PDF

通过 .NET SDK 向 PDF 添加 FreeText 注释

用于通过 .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. 将注释提交到指定页面。
  4. 下载修改后的文档以供本地使用。
 

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


    using Aspose.Pdf.Cloud.Sdk.Model;

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

                List<FreeTextAnnotation> annotations = new List<FreeTextAnnotation>
                {
                    new FreeTextAnnotation(
                        Name: "Freetext_NEW_Annotation",
                        Rect: new Rectangle(100,350, 450,400),
                        Flags: new List<AnnotationFlags>() { AnnotationFlags.Default },
                        HorizontalAlignment: HorizontalAlignment.Left,
                        Intent: FreeTextIntent.FreeTextTypeWriter,
                        Justification: Justification.Center,
                        RichText: helper.config.NEW_FT_ANNOTATION_TEXT,
                        Subject: helper.config.NEW_FT_ANNOTATION_SUBJECT,
                        Contents: helper.config.NEW_FT_ANNOTATION_CONTENTS,
                        Title: helper.config.NEW_FT_ANNOTATION_DESCRIPTION,
                        ZIndex: 1,
                        TextStyle: new TextStyle(
                            FontSize:        20,
                            Font: "Arial",
                            ForegroundColor: new Color( A: 0xFF, R: 0x00, G: 0xFF, B: 0x00),
                            BackgroundColor: new Color( A: 0xFF, R: 0xFF, G: 0x00, B: 0x00)
                        ),
                        Modified: "03/27/2025 00:00:00.000 AM"
                    )
                };
                AsposeResponse response = await helper.pdfApi.PostPageFreeTextAnnotationsAsync(documentName, pageNumber, annotations, folder: remoteFolder);

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