HTML
JPG
PDF
XML
DOCX
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 StartedHow 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.
- Uploads the PDF to cloud storage.
- Creates a new highlight annotation with defined position, color, text, and styling.
- Sends the annotation to the specified page using the Aspose Cloud API.
- Checks the response and logs the result.
- Downloads the updated file for local use.
This sample code shows adding annotations to PDF document
public static async Task AddHighlightAnnotation()
{
const string localPdfDocumentName = @"C:\Samples\sample.pdf";
const string storageFileName = "sample.pdf";
const string localFolder = @"C:\\Samples";
const string resultFileName = "output_add_hl_annotation.pdf";
const int pageNumber = 1;
// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required).
var pdfApi = new PdfApi(AppSecret, AppSid);
var filesOnStorage = await pdfApi.GetFilesListAsync("");
if (filesOnStorage.Value.All(f => f.Name != storageFileName))
{
using var file = File.OpenRead(localPdfDocumentName);
var uploadResult = await pdfApi.UploadFileAsync(storageFileName, file);
Console.WriteLine(uploadResult.Uploaded[0]);
}
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: "NEW HIGHLIGHT TEXT ANNOTATION",
Subject: "Highlight Text Box Subject",
Contents: "Highlight annotation sample contents",
Title: "This is a sample highlight annotation",
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 pdfApi.PostPageHighlightAnnotationsAsync(storageFileName, pageNumber, annotations);
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
{
await (await pdfApi.DownloadFileAsync(storageFileName))
.CopyToAsync(File.Create(Path.Combine(localFolder, resultFileName)));
Console.WriteLine("NewHighlightAnnotation(): annotation added to the document '{0}.", storageFileName);
}
}