Removing attachment from PDF

Contents
[ ]

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

The following code snippet also work with Aspose.PDF.Drawing library.

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.

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void DeleteAllAttachments()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Attachments();

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "DeleteAllAttachments.pdf"))
    {
        // Delete all attachments
        document.EmbeddedFiles.Delete();

        // Save PDF document
        document.Save(dataDir + "DeleteAllAttachments_out.pdf");
    }
}