Image Operations

The current Java PdfContentEditorExamples class directly supports replaceImage(...).

Replace an image

  1. Bind the source PDF to the PdfContentEditor facade.
  2. Call replaceImage(...) with the page number, image index, and replacement image path.
  3. 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();
    }
}