페이지의 텍스트 바꾸기

Contents
[ ]

텍스트 교체는 PDF 문서를 업데이트할 때 일반적으로 필요한 요구 사항입니다.사용 PDF 콘텐츠 편집기, 특정 텍스트를 검색하고 새 내용으로 바꿀 수 있습니다.‘replace_text_strategy ‘속성을 사용하면 대체되는 항목 수를 제어할 수 있습니다.

  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_on_page(infile, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # Replace text on page 1
    content_editor.replace_text_strategy.replace_scope = (
        pdf_facades.ReplaceTextStrategy.Scope.REPLACE_FIRST
    )
    content_editor.replace_text("PDF", "Page 1 Replaced Text", 14)
    # Save updated document
    content_editor.save(outfile)