Delete Images from PDF File
Contents
[
Hide
]
The following code snippet also work with Aspose.PDF.Drawing library.
To delete an image from a PDF file:
- Create a Document object and open the input PDF file.
- Get the Page that holds the image from the Document object’s Pages collection.
- Images are held in the Images collection, found in the page’s Resources collection.
- Delete an image with the Images collection’s Delete method.
- 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 pdfDocument = new Document(dataDir+ "DeleteImages.pdf");
// Delete a particular image
pdfDocument.Pages[1].Resources.Images.Delete(1);
dataDir = dataDir + "DeleteImages_out.pdf";
// Save updated PDF file
pdfDocument.Save(dataDir);