استبدال النص بالحالة

Contents
[ ]

عند تحديث النص في PDF، قد ترغب في إبراز المحتوى البديل. باستخدام كائن TextState، يمكنك تحديد التصميم مثل اللون وحجم الخط، ثم تطبيقه على كل النص الذي تم استبداله.

  1. قم بإنشاء محرر محتوى PDF مثال.
  2. قم بربط وثيقة PDF المدخلة.
  3. حدد TextState بتنسيق مخصص.
  4. قم بتكوين نطاق الاستبدال.
  5. استبدل النص عبر المستند بأكمله.
  6. احفظ مستند 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_with_state(infile, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)

    text_state = ap.text.TextState()
    text_state.foreground_color = ap.Color.blue
    text_state.font_size = 14

    # Replace text with explicit text formatting
    content_editor.replace_text_strategy.replace_scope = (
        pdf_facades.ReplaceTextStrategy.Scope.REPLACE_ALL
    )
    content_editor.replace_text("software", "SOFTWARE", text_state)
    # Save updated document
    content_editor.save(outfile)