HTML
JPG
PDF
XML
DOCX
PDF
Add underline text annotations to PDF documents via .NET SDK
API for adding underline text annotations to PDF documents using As[pse.PDF Cloud .NET SDK.
Get StartedHow to insert underline 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 a PDF to cloud storage.
- Creates a green underline annotation with rich metadata.
- Applies it to a specific page.
- Handles the server response.
- Downloads the updated file.
This sample code shows adding underline annotations to PDF document
public static async Task AddUnderlineAnnotation()
{
const string localPdfDocument = @"C:\Samples\sample.pdf";
const string storageFileName = "sample.pdf";
const string localFolder = @"C:\\Samples";
const string resultFileName = "output_add_ul_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<UnderlineAnnotation> annotations = new List<UnderlineAnnotation>
{
new UnderlineAnnotation(
Name: "Underline_NEW_Annotation",
Rect: new Rectangle(100,350, 450,400),
Flags: new List<AnnotationFlags>() { AnnotationFlags.Default },
HorizontalAlignment: HorizontalAlignment.Left,
VerticalAlignment: VerticalAlignment.Top,
RichText: "NEW UNDERLINE ANNOTATION 2",
Subject: "Underline Box Subject 2",
Contents: "Underline annotation sample contents 2",
Title: "This is an underline annotation 2",
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.PostPageUnderlineAnnotationsAsync(storageFileName, pageNumber, annotations);
if (response == null)
Console.WriteLine("AddUnderlineAnnotation(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("AddUnderlineAnnotation(): Failed to append underline annotation to the document.");
else
{
await (await pdfApi.DownloadFileAsync(storageFileName))
.CopyToAsync(File.Create(Path.Combine(localFolder, resultFileName)));
Console.WriteLine("NewUnderlineAnnotation(): annotation added to the document '{0}.", resultFileName);
}
}