Remove Images from PDF document via Java

Delete images from PDF document using Aspose.PDF for Java Library

Remove Images from PDF Document Using Java Library

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

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java AP</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>

Delete Images from PDF using Java


You need Aspose.PDF for Java to try the code in your environment.

  1. Open existing PDF Document.
  2. Delete a particular image.
  3. Save updated PDF file.

Delete Images from Existing PDF File - Java

This sample code shows how to remove Images from PDF - Java

String inputFile = DATA_DIR.resolve("DeleteImages.pdf").toString();
String outputFile = DATA_DIR.resolve("DeleteImages_out.pdf").toString();
Document pdfDocument = new Document(inputFile);
pdfDocument.getPages().get_Item(1).getResources().getImages().delete(1);
pdfDocument.save(outputFile);
pdfDocument.close();