HTML
JPG
PDF
XML
DOCX
PDF
Replace Text Annotations in PDF via .NET SDK
API for replacing annotations in PDF documents with Aspose.PDF Cloud .NET SDK.
Get StartedHow to Replace Text annotations in PDF documents using Cloud .NET SDK
For replacing text annotations in PDF documents, 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 replace annotations using .NET SDK
Aspose.PDF Cloud developers can easily load & replace annotations in PDF documents in just a few lines of code.
- Uploads the document to the cloud.
- Get Annotation using GetTextAnnotationAsync().
- Modify Annotation Contents and Icon.
- Save the Changes Back to the Cloud
- Downloads the updated document.
This sample code shows replacing Text Annotations in PDF document via C#
using Aspose.Pdf.Cloud.Sdk.Model;
using System.Runtime.Intrinsics.X86;
namespace Annotations
{
public class ReplaceAnnotation
{
public static async Task<TextAnnotation> GetAnnotationAsync(AnnotationsHelper helper, string documentName, string annotationId, string remoteFolder)
{
// Get annotation by Id in the PDF document.
TextAnnotation annotationResult = null;
TextAnnotationResponse response = await helper.pdfApi.GetTextAnnotationAsync(documentName, annotationId, folder: remoteFolder);
if (response == null)
Console.WriteLine("GetAnnotationAsync(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("GetAnnotationAsync(): Failed to request text annotation from the document.");
else
{
Console.WriteLine("GetAnnotationAsync(): annotation '{0}' with '{1}' contents successfully found in the document '{2}.", response.Annotation.Id, response.Annotation.Contents, documentName);
annotationResult = response.Annotation;
}
return annotationResult;
}
public static async Task ModifyAsync(AnnotationsHelper helper, string documentName, string outputName, string annotationId, string remoteFolder)
{
// Change annotation on the page in the PDF document.
await helper.UploadFile(documentName);
TextAnnotation annotation = await ReplaceAnnotation.GetAnnotationAsync(helper, documentName, annotationId, remoteFolder);
annotation.Contents = helper.config.REPLACED_CONTENT;
annotation.Icon = TextIcon.Star;
TextAnnotationResponse response = await helper.pdfApi.PutTextAnnotationAsync(documentName, annotationId, annotation, folder: remoteFolder);
if (response == null)
Console.WriteLine("ModifyAnnotation(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("ModifyAnnotation(): Failed to request text annotation from the document.");
else
{
Console.WriteLine("ModifyAnnotation(): annotation '{0}' successfully modified in the document '{1}.", annotationId, documentName);
await helper.DownloadFile(documentName, outputName, "replaced_annotatiom_");
}
}
}
}