HTML JPG PDF XML DOCX
  Product Family
PDF

Add highlight text annotations to PDF documents via .NET SDK

API for adding highlight text annotations to PDF documents using Aspose.PDF Cloud .NET SDK.

Get Started

How to insert highlight text annotations to PDF documents using Cloud .NET SDK

In order to add annotations to PDF documents via Cloud .NET SDK , we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in C#, ASP.NET, or other .NET languages for various cloud platforms. Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


    PM> Install-Package Aspose.Pdf-Cloud
     

Steps to add annotations using .NET SDK

Aspose.PDF Cloud developers can easily load & append annotations to PDF documents in just a few lines of code.

  1. Uploads the PDF to cloud storage.
  2. Creates a new highlight annotation with defined position, color, text, and styling.
  3. Sends the annotation to the specified page using the Aspose Cloud API.
  4. Checks the response and logs the result.
  5. Downloads the updated file for local use.
 

This sample code shows adding annotations to PDF document


    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_");
                }
            }
        }
    }