PNG JPG BMP TIFF PDF
Aspose.PDF  for Python

Remplacer les annotations de texte dans les PDF via Python SDK

API pour remplacer les annotations dans les documents PDF à l’aide de Cloud Python SDK.

Get Started

Comment remplacer les annotations de texte dans un PDF via Cloud Python SDK

Pour remplacer les annotations de texte dans un PDF, nous utiliserons Aspose.PDF Cloud Python SDK. Ce SDK Cloud aide les programmeurs Python à développer des applications de création, d’annotation, d’édition et de conversion de PDF basées sur le cloud en utilisant le langage de programmation Python via Aspose.PDF REST API. Créez simplement un compte sur Aspose for Cloud et obtenez les informations de votre application. Une fois que vous avez l’App SID et la clé, vous êtes prêt à utiliser Aspose.PDF Cloud Python SDK. Si le package Python est hébergé sur Github, vous pouvez l’installer directement depuis Github :

Installation depuis Github


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

Commande Console du Gestionnaire de Packages

     
    pip install asposepdfcloud

Étapes pour remplacer les annotations de texte dans un PDF via Python

Les développeurs d’Aspose.PDF Cloud peuvent facilement charger et remplacer les annotations de texte dans un PDF en seulement quelques lignes de code.

  1. Installez Python SDK.
  2. Obtenez l’annotation en utilisant get_text_annotation().
  3. Modifiez le contenu et l’icône de l’annotation.
  4. Soumettez la mise à jour.
  5. Validez la réponse.
  6. Téléchargez le document mis à jour.
 

Remplacer les annotations de texte dans un PDF en utilisant 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}")