Ganti Teks Sederhana

Contents
[ ]

Penggantian teks sederhana berguna saat memperbarui nilai berulang dalam sebuah dokumen. Dengan PdfContentEditor, Anda dapat menentukan ruang lingkup penggantian dan mengganti teks secara global di semua halaman.

  1. Buat sebuah PdfContentEditor instansi.
  2. Hubungkan dokumen PDF input.
  3. Konfigurasikan ruang lingkup penggantian untuk semua kemunculan.
  4. Ganti teks target.
  5. Simpan dokumen PDF yang diperbarui.
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)