This tutorial guides on how to remove image from PDF using Java. You will get the details to set the IDE, a list of steps, and a sample code to remove all images from PDF using Java on a selected page. You may delete all or selected images from a page based on the image index value.
Steps to Delete Image from PDF using Java
- Configure the IDE to use Aspose.PDF for Java to remove images from a PDF
- Load the source PDF file into the Document object for deleting pictures
- Access the target page from the loaded PDF with images in it
- Access the resources from the selected page
- Get a count of images in the resources and iterate through all the images
- Call the delete() method for each image in the collection
- Save the output PDF file with no images on the selected page
Follow these steps to learn how to delete image from PDF using Java. Each PDF page contains a collection of images in the resources that contain methods to delete images from the collection. Access each image and use the delete() method to remove it.
Code to Remove PIC from PDF using Java
This code demonstrates how to remove an image from a PDF using Java and repeat this process to remove all the images from a page. You may iterate through all the pages in the PDF starting from page 1 and remove all or selected images from the collection starting from index 1. Note that you cannot use index 1 for the page and image while working with this feature.
This article has taught us to remove pages from a PDF file. If you want to reverse the process i.e. insert an image, refer to the article on how to insert image into PDF using Java.