テキスト置換(シンプル)

ドキュメント全体のテキストの置換

  1. ソース PDF を PdfContentEditor ファサードにバインドしてください。
  2. 置換テキストの範囲を ReplaceAll に設定してください。
  3. 検索テキストと置換テキストを指定して replaceText(...) を呼び出してください。
  4. 更新された 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();
    }
}