텍스트를 상태로 바꾸기
Contents
[
Hide
]
PDF에서 텍스트를 업데이트할 때 대체 내용이 눈에 잘 띄도록 해야 할 수 있습니다.TextState 객체를 사용하여 색상 및 글꼴 크기와 같은 스타일을 정의한 다음 대체된 모든 텍스트에 적용할 수 있습니다.
- 만들기 PDF 콘텐츠 편집기 예.
- 입력 PDF 문서를 바인딩합니다.
- 사용자 지정 서식을 사용하여 TextState를 정의합니다.
- 교체 범위를 구성합니다.
- 전체 문서에서 텍스트를 바꿉니다.
- 업데이트된 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)