PNG
JPG
BMP
TIFF
PDF
استبدال التعليقات النصية في PDF عبر Python SDK
API لاستبدال التعليقات في مستندات PDF باستخدام Cloud Python SDK.
Get Startedكيفية استبدال التعليقات النصية في PDF عبر Cloud Python SDK
لاستبدال التعليقات النصية في PDF، سنستخدم Aspose.PDF Cloud Python SDK. يساعد هذا الـ Cloud SDK مبرمجي Python في تطوير تطبيقات إنشاء وتحرير وتحويل ملفات PDF القائمة على السحابة باستخدام لغة البرمجة Python عبر Aspose.PDF REST API. ببساطة قم بإنشاء حساب في Aspose for Cloud واحصل على معلومات التطبيق الخاصة بك. بمجرد أن تحصل على App SID & key، يمكنك البدء في استخدام Aspose.PDF Cloud Python SDK. إذا كان حزمة Python مستضافة على Github، يمكنك تثبيتها مباشرة من Github:
التثبيت من Github
pip install git+https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-python.git
أمر وحدة التحكم في مدير الحزم
pip install asposepdfcloud
خطوات استبدال التعليقات النصية في PDF عبر Python
يمكن لمطوري Aspose.PDF Cloud تحميل واستبدال التعليقات النصية في ملفات PDF بسهولة باستخدام بضعة أسطر من الكود.
- تثبيت Python SDK.
- الحصول على التعليق باستخدام get_text_annotation().
- تعديل محتويات التعليق والأيقونة.
- تقديم التحديث.
- التحقق من صحة الاستجابة.
- تحميل المستند المحدث.
استبدال التعليقات النصية في PDF باستخدام 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}")