Image Operations
Contents
[
Hide
]
The current Java PdfContentEditorExamples class directly supports replaceImage(...).
Replace an image
- Bind the source PDF to the
PdfContentEditorfacade. - Call
replaceImage(...)with the page number, image index, and replacement image path. - Save the updated PDF document.
public static void replaceImage(Path inputFile, Path imageFile, Path outputFile) {
PdfContentEditor editor = new PdfContentEditor();
try {
editor.bindPdf(inputFile.toString());
editor.replaceImage(1, 1, imageFile.toString());
editor.save(outputFile.toString());
} finally {
editor.close();
}
}