Replace Text Simple

Replace text throughout the document

  1. Bind the source PDF to the PdfContentEditor facade.
  2. Set the replace-text scope to ReplaceAll.
  3. Call replaceText(...) with the search text and replacement text.
  4. Save the updated PDF document.
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();
    }
}