HTML JPG PDF XML DOCX
  Product Family
PDF

Get Annotations from PDF via Python SDK

API for extracting annotations from PDF documents with Python

Get Started

Most popular actions with delete Annotations in Pdf documents via Python

How to extract annotations from PDF documents using Cloud Python SDK

In order to extract annotations from PDF documents via Cloud Python SDK , 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 extract annotations by Id using Python SDK

Aspose.PDF Cloud developers can easily load & get annotations by Id from PDF documents in just a few lines of code.

  1. Uploads the PDF.
  2. Get annotation by Id from PDF document with specified Id.
  3. Logs details of each.
  4. Returns the ID of the first annotation (for further actions like editing or deletion).
 

This sample code shows deleting annotation by Id from PDF document


    from asposepdfcloud import PdfApi, ApiClient
    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 PdfGetAnnotationById:
        """Class for managing PDF annotations using Aspose PDF Cloud API."""
        def request_annotation(self):
            """Get annotation from the page in the PDF document."""
            localFolder = "C:\Samples"
            storageDocumentName = "sample.pdf"
            storageTempFolder = "TempPdfCloud"
            annotationID = "GE5TAOZTHA2CYMRZGUWDIMBZFQZTEMA"

            # 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.get_text_annotation(storageDocumentName, annotationID, **args)

                if response.code == 200:
                    logging.info(f"get_annotationn(): annotation '{annotationID}' successfully found '{response.annotation.contents}' in the document '{storageDocumentName}'.")
                else:
                    logging.error(f"get_annotation(): Failed to get annotation in the document. Response code: {response.code}")