Remove Images from PDF document via Python

Delete images from PDF document using Aspose.PDF for Python for .NET Library

Remove Images from PDF Document Using Python Library

In order to remove Image from PDF, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for python-net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Console

pip install aspose-pdf

Delete Images from PDF using Python


You need Aspose.PDF for Python via .NET 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 - Python

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

import aspose.pdf as apdf

from os import path

path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, outfile)

document = apdf.Document(path_infile)

# Delete particular image
document.pages[2].resources.images.delete(1)

# Save updated PDF file
document.save(path_outfile )