テキスト置換(シンプル)
Contents
[
Hide
]
ドキュメント全体のテキストの置換
- ソース PDF を
PdfContentEditorファサードにバインドしてください。 - 置換テキストの範囲を
ReplaceAllに設定してください。 - 検索テキストと置換テキストを指定して
replaceText(...)を呼び出してください。 - 更新された PDF ドキュメントを保存してください。
public static void replaceTextSimple(Path inputFile, Path outputFile) {
PdfContentEditor editor = new PdfContentEditor();
try {
editor.bindPdf(inputFile.toString());
editor.getReplaceTextStrategy().setReplaceScope(ReplaceTextStrategy.Scope.ReplaceAll);
editor.replaceText("33", "XXXIII ");
editor.save(outputFile.toString());
} finally {
editor.close();
}
}