HTML JPG PDF XML DOCX
  Product Family
PDF

Delete Annotations from PDF via .NET SDK

API for remove annotations from PDF documents with .NET.

Get Started

How to delete annotations from PDF documents using Cloud .NET SDK

In order to work with annotations in 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 remove annotations using .NET SDK

Aspose.PDF Cloud developers can easily load & append annotations to PDF documents in just a few lines of code.

  1. Uploads the PDF.
  2. Creates a styled text box (with fonts, colors, alignment).
  3. Submits the annotation to the specified page.
  4. Downloads the modified document for local use.
 

This sample code shows removing Annotations from PDF document via C#


    public async static Task DeleteAnnotation()
    {
        const string localPdfDocument = @"C:\Samples\sample.pdf";
        const string storageFileName = "sample.pdf";
        const string localFolder = @"C:\\Samples";
        const string resultFileName = "output_del_annotations.pdf";
        const string annotationId = "GE5TMOZRGAYCYMZVGAWDINJQFQ2DAMA";

        // 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.DeleteAnnotationAsync(storageFileName, annotationId);
        if (response == null)
            Console.WriteLine("DeleteTextAnnotation(): Unexpected error!");
        else if (response.Code < 200 || response.Code > 299)
            Console.WriteLine("DeleteTextAnnotation(): Failed to delete annotation from the document.");
        else
        {
            await (await pdfApi.DownloadFileAsync(storageFileName))
                .CopyToAsync(File.Create(Path.Combine(localFolder, resultFileName)));
            Console.WriteLine("DeleteTextAnnotation(): annotation deleted from the document '{0}.", resultFileName);
        }
    }