ステートでテキストの置換
Contents
[
Hide
]
カスタム TextState でテキストの置換
- ソース PDF を
PdfContentEditorファサードにバインドしてください。 - 必要なカラーとフォントサイズで
TextStateを作成して構成してください。 - 置換テキストのスコープを
ReplaceAllに設定してください。 replaceText(...)を呼び出し、検索テキスト、置換テキスト、および設定済みのTextStateを渡してください。- 更新された PDF ドキュメントを保存してください。
public static void replaceTextWithState(Path inputFile, Path outputFile) {
PdfContentEditor editor = new PdfContentEditor();
try {
editor.bindPdf(inputFile.toString());
TextState textState = new TextState();
textState.setForegroundColor(com.aspose.pdf.Color.getBlue());
textState.setFontSize(14);
editor.getReplaceTextStrategy().setReplaceScope(ReplaceTextStrategy.Scope.ReplaceAll);
editor.replaceText("software", "SOFTWARE", textState);
editor.save(outputFile.toString());
} finally {
editor.close();
}
}