PNG
JPG
BMP
TIFF
PDF
Get Page Annotations from PDF via Python SDK
API for getting annotations from PDF documents using Cloud Python SDK.
Get StartedHow to get page annotations from PDF via Cloud Python SDK
To get 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 get page annotations from PDF via Python
Aspose.PDF Cloud developers can easily load & get page annotations from PDF in just a few lines of code.
- Install Python SDK.
- Uploads the PDF to cloud storage.
- Retrieves all annotations from a specified page.
- Logs details of each.
- Returns the ID of the first Text annotation (for further actions like editing or deletion).
Get Page Annotations from PDF using Python
from annotations_helper import Config, PdfAnnotationsHelper, logging
from asposepdfcloud import PdfApi, AnnotationsInfoResponse
class PdfGetAnnotations:
"""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 request_annotations(self):
"""Get annotations from the page in the PDF document."""
if self.pdfApi:
self.helper.uploadFile(Config.PDF_DOCUMENT_NAME, Config.LOCAL_FOLDER, Config.REMOTE_FOLDER)
args = {
"folder": Config.REMOTE_FOLDER
}
annotation_result = ''
response: AnnotationsInfoResponse = self.pdfApi.get_page_annotations(Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER, **args)
if response.code == 200:
for annotation in response.annotations.list:
if annotation.annotation_type == "Text":
logging.info(f"get_annotations(): annotation id={annotation.id} with '{annotation.contents}' content get from the document '{Config.PDF_DOCUMENT_NAME}' on {annotation.page_index} page.")
annotation_result = annotation.id
return annotation_result
else:
logging.error(f"get_annotations(): Failed to get annotation in the document. Response code: {response.code}")
return annotation_result