Delete Images from PDF File

Contents
[ ]

The following code snippet also work with Aspose.PDF.Drawing library.

To delete an image from a PDF file:

  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.

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();

// Open document
Document document = new Document(dataDir +  "DeleteImages.pdf");

// Delete a particular image
document.Pages[1].Resources.Images.Delete(1);

// Save updated PDF file
document.Save(dataDir + "DeleteImages_out.pdf");