HTML
JPG
PDF
XML
DOCX
PDF
Delete annotations from PDF document pages via .NET SDK
API for removing annotations from PDF document pages with Aspose.PDF Cloud .NET SDK.
Get StartedHow to delete annotations from PDF document pages using Cloud .NET SDK
For removing page annotations from 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 remove annotations using .NET SDK
Aspose.PDF Cloud developers can easily load & delete annotations to PDF documents in just a few lines of code.
- Uploads the input PDF.
- Deletes all annotations from a specified page.
- Handles errors and reports status.
- Downloads the cleaned-up PDF file.
This sample code shows removing Page Annotations from PDF document via C#
public async static Task DeletePageAnnotations()
{
const string localPdfDocument = @"C:\Samples\sample.pdf";
const string storageFileName = "sample.pdf";
const string localFolder = @"C:\\Samples";
const string resultFileName = "output_del_page_annotations.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]);
}
AsposeResponse response = await pdfApi.DeletePageAnnotationsAsync(storageFileName, pageNumber);
if (response == null)
Console.WriteLine("DeletePageAnnotations(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("DeletePageAnnotations(): Failed to delete annotation from the document.");
else
{
await (await pdfApi.DownloadFileAsync(storageFileName))
.CopyToAsync(File.Create(Path.Combine(localFolder, resultFileName)));
Console.WriteLine("DeletePageAnnotations(): annotations deleted from document '{0} page {1}.", resultFileName, pageNumber);
}
}