PNG
JPG
BMP
TIFF
PDF
Thay thế Chú thích Văn bản trong PDF qua Python SDK
API để thay thế chú thích trong tài liệu PDF sử dụng Cloud Python SDK.
Get StartedCách thay thế chú thích văn bản trong PDF qua Cloud Python SDK
Để thay thế chú thích văn bản trong PDF, chúng tôi sẽ sử dụng Aspose.PDF Cloud Python SDK. 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 sử dụ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 Console Quản lý Gói
pip install asposepdfcloud
Các bước thay thế chú thích văn bản trong PDF qua Python
Các nhà phát triển Aspose.PDF Cloud có thể dễ dàng tải & thay thế chú thích văn bản trong PDF chỉ với vài dòng mã.
- Cài đặt Python SDK.
- Lấy Chú thích sử dụng get_text_annotation().
- Chỉnh sửa Nội dung và Biểu tượng của Chú thích.
- Gửi Cập nhật.
- Xác nhận Phản hồi.
- Tải xuống tài liệu đã cập nhật.
Thay thế Chú thích Văn bản trong PDF sử dụng Python
from annotations_helper import Config, PdfAnnotationsHelper, logging
from asposepdfcloud import PdfApi, TextAnnotationResponse
class PdfReplaceAnnotations:
"""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 _get_annotation(self, annotation_id):
"""Get annotation from the page in the PDF document."""
if self.pdfApi:
args = {
"folder": Config.REMOTE_FOLDER
}
response: TextAnnotationResponse = self.pdfApi.get_text_annotation(Config.PDF_DOCUMENT_NAME, annotation_id, **args)
if response.code == 200:
logging.info(f"get_annotationn(): annotation '{annotation_id}' successfully found '{response.annotation.contents}' in the document '{Config.PDF_DOCUMENT_NAME}'.")
return response.annotation
else:
logging.error(f"get_annotation(): Failed to get annotation in the document. Response code: {response.code}")
return None
def modify_annotation(self):
if self.pdfApi:
if Config.ANNOTATION_ID:
self.helper.uploadFile(Config.PDF_DOCUMENT_NAME, Config.LOCAL_FOLDER, Config.REMOTE_FOLDER)
args = {
"folder": Config.REMOTE_FOLDER
}
annotation = self._get_annotation(Config.ANNOTATION_ID)
annotation.contents = Config.REPLACED_CONTENT
annotation.icon = "Star"
response = self.pdfApi.put_text_annotation(Config.PDF_DOCUMENT_NAME, Config.ANNOTATION_ID, annotation, **args)
if response.code == 200:
logging.info(f"modify_annotation(): annotation '{annotation.id}' successfully modified in the document '{Config.PDF_DOCUMENT_NAME}'.")
self.helper.downloadFile(Config.PDF_DOCUMENT_NAME, Config.LOCAL_RESULT_DOCUMENT_NAME, Config.LOCAL_FOLDER, Config.REMOTE_FOLDER, "replaced_annotatiom_")
else:
logging.error(f"modify_annotation(): Failed to modify annotation in the document. Response code: {response.code}")