Removing attachment from an existing PDF

Contents
[ ]

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

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 delete all the attachments from a PDF document.

   public static void DeleteAllAttachmentsFromPDF(){
  // Open a document
  Document pdfDocument = new Document(_dataDir+"input.pdf");
  // Delete all attachments
  pdfDocument.getEmbeddedFiles().delete();
  // Save the updated file
  pdfDocument.save("output.pdf");

    }