Add text annotations to PDF documents via .NET SDK
API for adding text annotations to PDF documents using Aspose.PDF Cloud .NET SDK.
Get StartedHow to append text annotations to PDF documents using Aspose.PDF 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: PM> Install-Package Aspose.Pdf-Cloud
Steps to add text 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.
- Creates a styled text box (with fonts, colors, alignment).
- Submits the annotation to the specified page.
- Downloads the modified document for local use.
This sample code shows adding text annotations to PDF document
public static async Task AddTextAnnotation()
{
const string localPdfDocument = @"C:\Samples\sample.pdf";
const string storageFileName = "sample.pdf";
const string localFolder = @"C:\\Samples";
const string resultFileName = "output_add_text_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(localPdfDocument);
var uploadResult = await pdfApi.UploadFileAsync(storageFileName, file);
Console.WriteLine(uploadResult.Uploaded[0]);
}
List<TextAnnotation> annotations = new List<TextAnnotation>
{
new TextAnnotation(
Rect: new Rectangle(100, 450, 450,500),
Color: new Color( A: 0xFF, R: 0x00, G: 0xFF, B: 0x00),
Flags: new List<AnnotationFlags>() { AnnotationFlags.Default },
HorizontalAlignment: HorizontalAlignment.Left,
RichText: "NEW TEXT ANNOTATION 2",
Subject: "Text Box Subject 2",
Contents: "Text annotation sample contents 2",
Title: "This is a text annotation 2",
ZIndex: 1,
Icon: TextIcon.Key,
Modified: "03/27/2025 00:00:00.000 AM"
)
};
AsposeResponse response = await pdfApi.PostPageTextAnnotationsAsync(storageFileName, pageNumber, annotations);
if (response == null)
Console.WriteLine("NewTextAnnotation(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("NewTextAnnotation(): Failed to append text annotation to the document.");
else
{
await (await pdfApi.DownloadFileAsync(storageFileName))
.CopyToAsync(File.Create(Path.Combine(localFolder, resultFileName)));
Console.WriteLine("NewTextAnnotation(): annotation added to the document '{0}.", resultFileName);
}
}
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Why Aspose.PDF Cloud for .NET?
- Customers List
- Security