GroupDocsGists
10/24/2017 - 1:02 PM

RemoveAttachmentPDF.cs

using (PdfDocument doc = Document.Load<PdfDocument>(Utilities.MapSourceFilePath(FilePath)))
{
    for (int i = doc.Attachments.Count - 1; i >= 0; i--)
    {
        PdfAttachment attachment = doc.Attachments[i];

        // Remove all attached pdf files with a particular name
        if (attachment.Name.Contains("sample") && attachment.DocumentInfo.FileFormat == FileFormat.Docx)
        {
            doc.Attachments.RemoveAt(i);
        }
    }
    doc.Save();
}