PNG JPG BMP TIFF PDF
Aspose.PDF  for Python

Agregar Anotaciones de Texto Tachado a PDF a través de Python SDK

API para agregar anotaciones a documentos PDF usando Cloud Python SDK.

Get Started

Cómo agregar Anotaciones de Tachado a PDF a través de Cloud Python SDK

Para agregar anotaciones en PDF, usaremos Aspose.PDF Cloud Python SDK. Este SDK en la nube ayuda a los programadores de Python a desarrollar aplicaciones en la nube para crear, anotar, editar y convertir PDFs usando el lenguaje de programación Python a través de la API REST de Aspose.PDF. Simplemente cree una cuenta en Aspose for Cloud y obtenga la información de su aplicación. Una vez que tenga el App SID y la clave, estará listo para usar Aspose.PDF Cloud Python SDK. Si el paquete de Python se aloja en Github, puede instalarlo directamente desde Github:

Instalación desde Github


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

Comando de la Consola del Administrador de Paquetes

     
    pip install asposepdfcloud

Pasos para agregar anotaciones de tachado a PDF a través de Python

Los desarrolladores de Aspose.PDF Cloud pueden cargar y agregar anotaciones a PDF fácilmente en solo unas pocas líneas de código.

  1. Instale Python SDK.
  2. Cargue el PDF de entrada.
  3. Cree una nueva StrikeOutAnnotation con propiedades como posición, color y texto.
  4. Publique la Anotación en el PDF.
  5. Valide la respuesta.
  6. Descargue el Documento Anotado.
 

Agregar Anotaciones de Tachado a PDF usando Python


    from annotations_helper import Config, PdfAnnotationsHelper, logging
    from asposepdfcloud import PdfApi, StrikeOutAnnotation, Rectangle, Color, Point, AnnotationFlags, HorizontalAlignment, VerticalAlignment

    class PdfAddStrikeoutAnnotations:
        """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 append_strikeout_annotation(self):
            """Append a new strikeout text annotation to the PDF document."""
            if self.pdfApi:
                self.helper.uploadFile(Config.PDF_DOCUMENT_NAME, Config.LOCAL_FOLDER, Config.REMOTE_FOLDER)
                
                args = {
                    "folder": Config.REMOTE_FOLDER
                }
                
                new_annotation = StrikeOutAnnotation(
                    rect = Rectangle(llx=100, lly=100, urx=200, ury=200),
                    name = 'Strikeout_Text_Annotation',
                    flags = [AnnotationFlags.DEFAULT],
                    horizontal_alignment = HorizontalAlignment.LEFT,
                    vertical_alignment = VerticalAlignment.TOP,
                    rich_text = Config.NEW_SO_ANNOTATION_TEXT,
                    subject = Config.NEW_SO_ANNOTATION_SUBJECT,
                    title = Config.NEW_SO_ANNOTATION_DESCRIPTION,
                    contents= Config.NEW_SO_ANNOTATION_CONTENTS,
                    z_index = 1,
                    color= Color(a=0xFF, r=0, g=0xFF, b=0),
                    quad_points = [
                        Point(10, 10),
                        Point(20, 10),
                        Point(10, 20),
                        Point(10, 10)
                    ],
                    modified = '03/27/2025 00:00:00.000 AM',
                )
                try:
                    response = self.pdfApi.post_page_strike_out_annotations(Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER, [new_annotation], **args)
                    if response.code == 200:
                        logging.info(f"append_strikeout_annotation(): annotation '{Config.NEW_SO_ANNOTATION_TEXT}' added to the document '{Config.PDF_DOCUMENT_NAME}'.")
                        self.helper.downloadFile(Config.PDF_DOCUMENT_NAME, Config.LOCAL_RESULT_DOCUMENT_NAME, Config.LOCAL_FOLDER, Config.REMOTE_FOLDER, "add_strikeout_")
                    else:
                        logging.error(f"append_strikeout_annotation(): Failed to add annotation to the document. Response code: {response.code}")
                except Exception as e:
                    logging.error(f"append_strikeout_annotation(): Error while adding annotation: {e}")