In order to remove Image from PDF, we’ll use Aspose.PDF for Java API which is a feature-rich, powerful, and easy-to-use conversion API for the Java platform. You can download its latest version directly from Maven and install it within your Maven-based project by adding the following configurations to the pom.xml.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java AP</name>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>
Delete Images from PDF via Java
You need Aspose.PDF for Java to try the code in your environment.
- Open existing PDF Document.
- Delete a particular image.
- Save updated PDF file.
Delete Images from Existing PDF File - Java
// Open document
Document pdfDocument = new Document(_dataDir + "PageNumberStamp.pdf");
// Create page number stamp
PageNumberStamp pageNumberStamp = new PageNumberStamp();
// Whether the stamp is background
pageNumberStamp.setBackground(false);
pageNumberStamp.setFormat("Page # of " + pdfDocument.getPages().size());
pageNumberStamp.setBottomMargin (10);
pageNumberStamp.setHorizontalAlignment ( HorizontalAlignment.Center);
pageNumberStamp.setStartingNumber(1);
// Set text properties
pageNumberStamp.getTextState().setFont (FontRepository.findFont("Arial"));
pageNumberStamp.getTextState().setFontSize (14.0F);
pageNumberStamp.getTextState().setFontStyle (FontStyles.Bold);
pageNumberStamp.getTextState().setForegroundColor (Color.getAqua());
// Add stamp to particular page
pdfDocument.getPages().get_Item(1).addStamp(pageNumberStamp);
_dataDir = _dataDir + "PageNumberStamp_out.pdf";
// Save output document
pdfDocument.save(_dataDir);