Removing attachment from PDF using Python

Contents
[ ]

Aspose.PDF for Python can remove attachments from PDF files. A PDF document’s attachments are held in the Document object’s EmbeddedFiles collection.

To delete all attachments associated with a PDF file:

  1. Call the EmbeddedFiles collection’s delete() method.
  2. Save the updated file using the Document object’s save() method.

The following code snippet shows how to remove attachments from a PDF document.


    import aspose.pdf as ap

    # Open document
    document = ap.Document(input_pdf)

    # Delete all attachments
    document.embedded_files.delete()

    # Save updated file
    document.save(output_pdf)