Delete Images from PDF File

[ ]

To delete an image from a PDF file, simply use the Images collection’s delete(..) method.

  1. Create a Document object and open the input PDF file.
  2. Get the Page that holds the image from the Document object’s Pages collection.
  3. Images are held in the Images collection, found in the page’s Resources collection.
  4. Delete an image with the Images collection’s Delete method.
  5. Saved the output like using the Document object’s Save method.

The following code snippet shows how to delete an image from a PDF file.

package com.aspose.pdf.examples;

import com.aspose.pdf.Color;
import com.aspose.pdf.Document;
import com.aspose.pdf.FontRepository;
import com.aspose.pdf.FontStyles;
import com.aspose.pdf.HorizontalAlignment;
import com.aspose.pdf.PageNumberStamp;

public class ExampleDeleteImages {

    private static String _dataDir = "/home/admin1/pdf-examples/Samples/";

    public static void ExampleAddPageNumber() {

        // Open document
        Document pdfDocument = new Document(_dataDir + "PageNumberStamp.pdf");

        // Create page number stamp
        PageNumberStamp pageNumberStamp = new PageNumberStamp();

        // Whether the stamp is background
        pageNumberStamp.setFormat("Page # of " + pdfDocument.getPages().size());
        pageNumberStamp.setBottomMargin (10);
        pageNumberStamp.setHorizontalAlignment ( HorizontalAlignment.Center);
        // 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

        _dataDir = _dataDir + "PageNumberStamp_out.pdf";
        // Save output document;