Python 를 사용하여 PDF 편집

PDF 문서의 민감한 편집 정보.Python for .NET 용 Aspose.PDF 파일을 사용하여 프로그래밍 방식으로 PDF 문서를 수정하십시오.

Python 라이브러리를 사용하여 PDF 파일을 수정하는 방법

PDF 파일을 수정하려면 강력하고 사용하기 쉬운 API인 Aspose.PDF for Python.NET 을 사용하십시오.PyPI 를 열고 ‘aspose-pdf’를 검색하여 설치합니다.또는 다음 명령을 실행합니다.

Python 를 통해 PDF 문서 수정


사용자 환경에서 코드를 시험해 보려면 Aspose.PDF via .NET을 통한 파이썬용 이 필요합니다.

1.문서 인스턴스와 함께 PDF를 로드합니다. 1.검색어를 인수로 사용하여 TextFragmentAbsorber 객체를 생성합니다. 1.검색 옵션을 설정합니다. 1.각 조각 수집을 반복하여 수정하세요. 1.PDF 파일을 저장합니다.

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)