PNG JPG BMP TIFF PDF
Aspose.PDF  for Python

Trích Xuất Dấu Trang từ PDF trong Python SDK

Trích Xuất Dấu Trang vào Tài Liệu PDF bằng Cloud Python SDK.

Get Started

Cách trích xuất Dấu Trang từ PDF qua Cloud Python SDK

Để trích xuất Dấu Trang từ PDF, chúng tôi 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 các ứng dụng tạo, chú thích, chỉnh sửa và chuyển đổi PDF trên nền tảng đám mây bằng ngôn ngữ lập trình Python qua Aspose.PDF REST API. Chỉ cần tạo tài khoản tại Aspose for Cloud và nhận thông tin ứng dụng của bạn. Khi bạn có App SID & key, bạn đã sẵn sàng để 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 từ Gói Quản Lý

     
    pip install asposepdfcloud

Các bước để nhận Dấu Trang từ PDF qua Python SDK

Các nhà phát triển Aspose.PDF Cloud có thể dễ dàng tải & trích xuất Dấu Trang từ PDF chỉ trong vài dòng mã.

  1. Cài đặt Python SDK
  2. Tải tài liệu PDF lên máy chủ Aspose Cloud
  3. Nhận dấu trang cho tài liệu PDF cụ thể bằng cách sử dụng đường dẫn dấu trang
 

Trích Xuất Dấu Trang từ PDF bằng Python


    import shutil
    import json
    import logging
    from pathlib import Path
    from asposepdfcloud import ApiClient, PdfApi, BookmarkResponse

    # Configure logging
    logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")


    class Config:
        """Configuration parameters."""
        CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json")
        LOCAL_FOLDER = Path(r"C:\Samples")
        PDF_DOCUMENT_NAME = "sample.pdf"
        BOOKMARK_PATH = "/5"

    class PdfBookmarks:
        """Class for managing PDF bookmarks using Aspose PDF Cloud API."""

        def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE):
            self.pdf_api = None
            self._init_api(credentials_file)

        def _init_api(self, credentials_file: Path):
            """Initialize the API client."""
            try:
                with credentials_file.open("r", encoding="utf-8") as file:
                    credentials = json.load(file)
                    api_key, app_id = credentials.get("key"), credentials.get("id")
                    if not api_key or not app_id:
                        raise ValueError("Error: Missing API keys in the credentials file.")
                    self.pdf_api = PdfApi(ApiClient(api_key, app_id))
            except (FileNotFoundError, json.JSONDecodeError, ValueError) as e:
                logging.error(f"Failed to load credentials: {e}")

        def upload_document(self):
            """Upload a PDF document to the Aspose Cloud server."""
            if self.pdf_api:
                file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME
                try:
                    self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path))
                    logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.")
                except Exception as e:
                    logging.error(f"Failed to upload file: {e}")

        def get_bookmark(self):
            """Get bookmark for a specific PDF document using bookmark path."""    
            if self.pdf_api:
                try:
                    response : BookmarkResponse = self.pdf_api.get_bookmark( Config.PDF_DOCUMENT_NAME, Config.BOOKMARK_PATH)
                    if response.code == 200:
                        logging.info(f"Found bookmark => level: '{response.bookmark.level}' - action: '{response.bookmark.action}' - title: '{response.bookmark.title}'")
                    else:
                        logging.error(f"Failed to find bookmark for the document. Response code: {response.code}")
                except Exception as e:
                    logging.error(f"Error while find bookmark: {e}")

    if __name__ == "__main__":
        pdf_bookmarks = PdfBookmarks()
        pdf_bookmarks.upload_document()
        pdf_bookmarks.get_bookmark()
 

Làm việc với Dấu Trang trong PDF

Trích xuất dấu trang từ PDF cải thiện khả năng sử dụng tài liệu, tự động hóa xử lý nội dung và nâng cao khả năng tìm kiếm. Điều này đặc biệt hữu ích cho doanh nghiệp, nhà nghiên cứu và chuyên gia khi làm việc với các tài liệu PDF lớn hoặc có cấu trúc. Trích xuất Dấu Trang từ tài liệu PDF với Aspose.PDF Cloud Python SDK.

Với thư viện Python của chúng tôi, bạn có thể:

  • Kết hợp các tài liệu PDF.
  • Chia tách các Tệp PDF.
  • Chuyển đổi PDF sang các định dạng khác và ngược lại.
  • Thao tác Chú Thích.
  • Làm việc với Hình ảnh trong PDF, v.v.
  • Bạn có thể thử nghiệm ứng dụng miễn phí của chúng tôi để kiểm tra chức năng trực tuyến.