Delete Images from PDF File using Java

Use the page image resource collection when you need to remove embedded images from a PDF page.

Delete an embedded image by index

  1. Open the source PDF Document.
  2. Access the image resources on the target Page.
  3. Delete the target image from the page resource collection by its index.
  4. Save the updated PDF Document.
public static void deleteImage(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        document.getPages().get_Item(1).getResources().getImages().delete(1);
        document.save(outputFile.toString());
    }
}