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#
public static async Task ReplaceTextAnnotation()
{
const string localPdfDocument = @"C:\Samples\sample.pdf";
const string storageFileName = "sample.pdf";
const string localFolder = @"C:\\Samples";
const string resultFileName = "output_replace_annotations.pdf";
const string annotationId = "GE5TCNB3GEYDALBUGUYCYNBVGAWDKMBQ";
// 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]);
}
TextAnnotationResponse response = await pdfApi.GetTextAnnotationAsync(storageFileName, annotationId);
var annotation = response.Annotation;
annotation.Icon = TextIcon.Star;
annotation.Name = "Text_REPLACED_Annotation";
TextAnnotationResponse response2 = await pdfApi.PutTextAnnotationAsync(storageFileName, annotationId, annotation);
if (response == null)
Console.WriteLine("ReplaceTextAnnotation(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("ReplaceTextAnnotation(): Failed to replace annotations i the document.");
else
{
await (await pdfApi.DownloadFileAsync(storageFileName))
.CopyToAsync(File.Create(Path.Combine(localFolder, resultFileName)));
Console.WriteLine("ReplaceTextAnnotation(): annotation replaced in the document '{0}.", resultFileName);
}
}