Delete Images from PDF File using Java
Contents
[
Hide
]
Use the page image resource collection when you need to remove embedded images from a PDF page.
Delete an embedded image by index
- Open the source PDF Document.
- Access the image resources on the target Page.
- Delete the target image from the page resource collection by its index.
- 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());
}
}