Gerencie anotações em PDF via Python

Gerenciando anotações em documentos PDF. Use o Aspose.PDF for Python for .NET para modificar arquivos PDF de forma programática

Como gerenciar anotações usando a biblioteca Python for .NET

Para adicionar Anotação de texto no arquivo PDF, usaremos a API Aspose.PDF for .NET, que é uma API de manipulação de documentos rica em recursos, poderosa e fácil de usar para a plataforma python-net. Abra o gerenciador de pacotes NuGet, pesquise Aspose.pdf e instale. Você também pode usar o seguinte comando no Console do Gerenciador de Pacotes.

Console

pip install aspose-pdf

Crie anotações em um documento PDF via Python


Você precisa de Aspose.PDF para Python via .NET para testar o código em seu ambiente.

  1. Carregue PDF em uma instância da classe Document.
  2. Crie uma anotação que você deseja adicionar ao PDF.
  3. Adicione a anotação à coleção Annotations do objeto Page.
  4. Salve o arquivo PDF.

Anotação de texto em 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)