텍스트 단순 바꾸기

Contents
[ ]

간단한 텍스트 대체는 문서에서 반복되는 값을 업데이트할 때 유용합니다.를 사용하여 PDF 콘텐츠 편집기, 대체 범위를 정의하고 모든 페이지에서 텍스트를 전역으로 대체할 수 있습니다.

  1. 만들기 PDF 콘텐츠 편집기 예.
  2. 입력 PDF 문서를 바인딩합니다.
  3. 모든 항목에 대한 교체 범위를 구성합니다.
  4. 대상 텍스트를 바꿉니다.
  5. 업데이트된 PDF 문서를 저장합니다.
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades
import sys
from os import path

sys.path.append(path.join(path.dirname(__file__), ".."))

from config import set_license, initialize_data_dir


def replace_text_simple(infile, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # Replace text in the whole document
    content_editor.replace_text_strategy.replace_scope = (
        pdf_facades.ReplaceTextStrategy.Scope.REPLACE_ALL
    )
    content_editor.replace_text("33", "XXXIII ")
    # Save updated document
    content_editor.save(outfile)