Gestione las anotaciones en PDF a través de Python

Gestión de anotaciones en un documento PDF. Utilice Aspose.PDF for que Python for .NET modifique archivos PDF mediante programación

Cómo gestionar las anotaciones mediante la biblioteca de Python for .NET

Para agregar anotaciones de texto en un archivo PDF, usaremos la API Aspose.PDF for .NET, que es una API de manipulación de documentos rica en funciones, potente y fácil de usar para la plataforma python-net. Abra el administrador de paquetes NuGet, busque Aspose.pdf e instálelo. También puede usar el siguiente comando de la consola del administrador de paquetes.

Console

pip install aspose-pdf

Crear anotaciones en un documento PDF a través de Python


Necesita Aspose.PDF para Python a través de.NET para probar el código en su entorno.

  1. Cargue el PDF en una instancia de la clase Document.
  2. Cree una anotación que quiera añadir al PDF.
  3. Agregue la anotación a la colección Annotations del objeto Page.
  4. Guarde el archivo PDF.

Anotación de texto en PDF: Python

Example: Python

import aspose.pdf as apdf

from os import path

path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, outfile)

document = apdf.Document(path_infile)

appearance = apdf.annotations.DefaultAppearance()
appearance.font_size = 12
appearance.font_name = "Arial"

freeTextAnnotation = apdf.annotations.FreeTextAnnotation(
    document.pages[1],
    apdf.Rectangle(299.988, 703.664, 508.708, 720.769, True),
    appearance
)
freeTextAnnotation.contents = "This is a free text annotation."
freeTextAnnotation.name = "FreeText1"
freeTextAnnotation.subject = "Revision 01"
freeTextAnnotation.title = "Free Text Annotation"
freeTextAnnotation.popup = apdf.annotations.PopupAnnotation(
    document.pages[1], apdf.Rectangle(299.988, 713.664, 308.708, 720.769, True)
)
freeTextAnnotation.popup.open = True
document.pages[1].annotations.add(freeTextAnnotation, consider_rotation=False)
document.save(path_outfile)