Redija o PDF via Python

Informações de redação confidenciais de documentos PDF. Use o Aspose.PDF for Python for .NET para modificar documentos PDF programaticamente

Como redigir um arquivo PDF usando a biblioteca Python

Para redigir um ficheiro PDF, utilize Aspose.PDF for Python via .NET, uma API poderosa e fácil de utilizar. Abra o PyPI, pesquise por aspose-pdf e instale-o. Em alternativa, execute o comando:

Redija documentos PDF via Python


Você precisa Aspose.PDF for .NET testar o código em seu ambiente.

  1. Carregue o PDF com uma instância do Document.
  2. Crie um objeto TextFragmentAbsorber com termos de pesquisa como argumento.
  3. Defina as opções de pesquisa.
  4. Percorra cada fragmento coletado para redigir.
  5. Salve o arquivo PDF.

Redija arquivos PDF - 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)

searchTerm = "Secret word"
textFragmentAbsorber = apdf.text.TextFragmentAbsorber(searchTerm)
textSearchOptions = apdf.text.TextSearchOptions(True)
textFragmentAbsorber.text_search_options = textSearchOptions

document.pages.accept(textFragmentAbsorber)
textFragmentCollection = textFragmentAbsorber.text_fragments
for textFragment in textFragmentCollection:
    page = textFragment.page
    annotationRectangle = textFragment.rectangle
    annot = apdf.annotations.RedactionAnnotation(page, annotationRectangle)
    annot.fill_color = apdf.Color.black
    document.pages[page.number].annotations.add(annot, True)
    annot.redact()

    document.save(path_outfile)