PNG JPG BMP TIFF PDF
Aspose.PDF  cho Python

Lấy Chú Thích Trang từ PDF qua Python SDK

API để lấy chú thích từ tài liệu PDF bằng Cloud Python SDK.

Get Started

Cách lấy chú thích trang từ PDF qua Cloud Python SDK

Để lấy chú thích trang từ PDF, chúng ta sẽ sử dụng Aspose.PDF Cloud Python SDK. Cloud SDK này hỗ trợ các lập trình viên Python phát triển ứng dụng tạo, chú thích, chỉnh sửa, và chuyển đổi PDF dựa trên đám mây bằng ngôn ngữ lập trình Python qua Aspose.PDF REST API. Đơn giản chỉ cần tạo tài khoản tại Aspose for Cloud và lấy thông tin ứng dụng của bạn. Khi đã có App SID & key, bạn có thể bắt đầu sử dụng Aspose.PDF Cloud Python SDK. Nếu gói python được lưu trữ trên Github, bạn có thể cài đặt trực tiếp từ Github:

Cài đặt từ Github


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

Lệnh Console Quản lý Gói

     
    pip install asposepdfcloud

Các bước để lấy chú thích trang từ PDF qua Python

Các nhà phát triển Aspose.PDF Cloud có thể dễ dàng tải và lấy chú thích trang từ PDF chỉ với vài dòng mã.

  1. Cài đặt Python SDK.
  2. Tải lên PDF lên lưu trữ đám mây.
  3. Truy xuất tất cả chú thích từ một trang cụ thể.
  4. Ghi lại chi tiết của từng chú thích.
  5. Trả về ID của chú thích Văn bản đầu tiên (để thực hiện các hành động tiếp theo như chỉnh sửa hoặc xóa).
 

Lấy Chú Thích Trang từ PDF bằng 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