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.

Python Package Manager Console

pip install aspose-pdf

Delete Images from PDF via Python


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

    input_file = DIR_INPUT + "sample_with_image.pdf"
    output_pdf = DIR_OUTPUT + "delete_image.pdf"
    # Open document
    document = ap.Document(input_file)

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

    # Save updated PDF file
    document.save(output_pdf)