PNG
JPG
BMP
TIFF
PDF
Delete text annotations from PDF documents via Python SDK
API for removing text annotations from PDF documents using Aspose.PDF Cloud Python SDK.
Get StartedHow 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.
- Install Python SDK.
- Deletes a specific annotation using delete_annotation().
- Handles the response to ensure success.
- Removes any related popup annotations.
- 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}")