PNG JPG BMP TIFF PDF
Aspose.PDF  for Python

Delete text annotations from PDF documents via Python SDK

API for removing text annotations from PDF documents using Aspose.PDF Cloud Python SDK.

Get Started

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

To delete text 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 text annotations from PDF via Python

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

  1. Install Python SDK.
  2. Deletes a specific annotation using delete_annotation().
  3. Handles the response to ensure success.
  4. Removes any related popup annotations.
  5. Downloads the updated document.
 

Delete Text Annotations from PDF using Python


    from annotations_helper import Config, PdfAnnotationsHelper, logging
    from asposepdfcloud import PdfApi

    class PdfDalTextAnnotations:
        """Class for managing PDF annotations using Aspose PDF Cloud API."""
        def __init__(self, pdf_api: PdfApi, helper: PdfAnnotationsHelper):
            self.pdfApi = pdf_api
            self.helper = helper

        def delete_annotation(self):
            """Delete annotation from the PDF document."""
            if self.pdfApi:
                if Config.ANNOTATION_ID is None:
                    logging.info(f"delete_annotation(): annotation id not defined!")
                    return
                self.helper.uploadFile(Config.PDF_DOCUMENT_NAME, Config.LOCAL_FOLDER, Config.REMOTE_FOLDER)

                args = {
                    "folder": Config.REMOTE_FOLDER
                }
                response = self.pdfApi.delete_annotation(Config.PDF_DOCUMENT_NAME, Config.ANNOTATION_ID, **args)
                self.helper.delete_popup_annotations(Config.ANNOTATION_ID)
                if response.code == 200:
                    logging.info(f"delete_annotation(): annotation '{Config.ANNOTATION_ID}' deleted from the document '{Config.PDF_DOCUMENT_NAME}'.")
                    self.helper.downloadFile(Config.PDF_DOCUMENT_NAME, Config.LOCAL_RESULT_DOCUMENT_NAME, Config.LOCAL_FOLDER, Config.REMOTE_FOLDER, "del_annotation_")
                else:
                    logging.error(f"delete_annotation(): Failed to delete annotation from the document. Response code: {response.code}")