PNG JPG BMP TIFF PDF
Aspose.PDF  for Python

Delete annotations from PDF document pages via Python SDK

API for removing annotations from PDF document pages using Aspose.PDF Cloud Python SDK.

Get Started

How to delete page annotations from PDF documents via Cloud Python SDK

To delete page annotations from PDF, we’ll use Aspose.PDF Cloud Python SDK. This Cloud SDK assists Python programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Python programming language via Aspose.PDF REST API. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Python SDK. If the python package is hosted on Github, you can install directly from Github:

Installation from Github


     
    pip install git+https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-python.git

Package Manager Console Command

     
    pip install asposepdfcloud

Steps to delete page annotations from PDF via Python

Aspose.PDF Cloud developers can easily load & delete page annotations from PDF in just a few lines of code.

  1. Install Python SDK.
  2. Uploads the PDF to cloud storage.
  3. Deletes all annotations from a specified page.
  4. Handles errors and reports status.
  5. Downloads the cleaned-up PDF file.
 

Delete Page Annotations from PDF using Python


    from asposepdfcloud import PdfApi, ApiClient
    import shutil
    import os
    import json
    from pathlib import Path
    import logging

    # Configure logging
    logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

    class PdfDelPageAnnotations:
        """Class for managing PDF annotations using Aspose PDF Cloud API."""
        def delete_page_annotations(self):
            """Delete annotation from the PDF document."""
            localFolder = "C:\Samples"
            storageDocumentName = "sample.pdf"
            storageTempFolder = "TempPdfCloud"
            outputFileName = "output_del_annotation.pdf"

            # Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
            self.pdf_api = PdfApi(ApiClient(AppSecret, AppSid))
            
            if self.pdf_api:
                file_path = localFolder + "/" + storageDocumentName
                self.pdf_api.upload_file(os.path.join(storageTempFolder, storageDocumentName), file_path)
                    
                args = {
                    "folder": storageTempFolder
                }

                response = self.pdf_api.delete_page_annotations(storageDocumentName, page_number=1, **args)
                if response.code == 200:
                    temp_file = self.pdf_api.download_file(storageTempFolder + '/' + storageDocumentName)
                    local_path = localFolder + '/' + outputFileName
                    shutil.move(temp_file, local_path)
                    logging.info(f"delete_annotation(): annotations deleted from the document '{outputFileName}' page.")
                else:
                    logging.error(f"delete_annotation(): Failed to delete annotation from the document. Response code: {response.code}")