テキストを簡単に置換

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)