Replace Text Simple
Contents
[
Hide
]
Replace text throughout the document
- Bind the source PDF to the
PdfContentEditorfacade. - Set the replace-text scope to
ReplaceAll. - Call
replaceText(...)with the search text and replacement text. - 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();
}
}