Skip to main content
All docs
V23.2

PdfFileAttachmentAnnotationFacade Class

Contains members used to manage file attachment annotations without access to their inner structure.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v23.2.Core.dll

NuGet Package: DevExpress.Pdf.Core

Declaration

public class PdfFileAttachmentAnnotationFacade :
    PdfMarkupAnnotationFacade

Remarks

Create File Attachment Annotations

The code sample below creates a file attachment annotation:

file attachment annotation

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Specify attachment data
    PdfFileAttachment attachment = new PdfFileAttachment()
    {
        CreationDate = DateTime.Now,
        Description = "This is my attached file.",
        FileName = "MyAttach.txt",
        Data = File.ReadAllBytes("..\\..\\FileToAttach.txt")
    };

    // Create a file attachment annotation
    PdfFileAttachmentAnnotationFacade pdfFileAttachment =
        pageFacade.AddFileAttachmentAnnotation
            (new PdfPoint(700,100), attachment, PdfFileAttachmentAnnotationIconName.PaperClip);
    pdfFileAttachment.Author = "Sabella Jaida";
    pdfFileAttachment.Subject = "Attachment";

    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}

Edit File Attachment Annotations

The PdfPageFacade.Annotations property returns all page annotation properties. You can filter file attachment annotation properties, cast them to the PdfFileAttachmentAnnotationFacade class, and use class properties to modify annotation parameters.

The code sample below retrieves all file attachment annotations on the first page and changes their parameters.

using DevExpress.Pdf;
using System.Linq;
//...
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Retrieve all file attachment annotations
    var fileAttachmentAnnotations = pageFacade.Annotations.Where
      (annotation => annotation.Type == PdfAnnotationType.FileAttachment);
    foreach(PdfFileAttachmentAnnotationFacade fileAttachmentAnnotation in fileAttachmentAnnotations) 
    {
        // Change annotation parameters
        fileAttachmentAnnotation.Color = new PdfRGBColor(0.36, 0.54, 0.66);
        fileAttachmentAnnotation.Author = "Tobias Rieper";
        fileAttachmentAnnotation.IconName = PdfFileAttachmentAnnotationIconName.Tag;
    }
    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}

Flatten File Attachment Annotations

Call one of the following methods to flatten an annotation:

Method Description
PdfDocumentFacade.FlattenAnnotations Flattens document annotations.
PdfPageFacade.FlattenAnnotations Flattens annotations of a specific page.
PdfAnnotationFacade.Flatten() Flattens a specific annotation.

The code sample below flattens all file attachment annotations on the first page. As a result, all embedded files are removed.

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Flatten annotations
    pageFacade.FlattenAnnotations(PdfAnnotationType.FileAttachment);

    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}

Remove File Attachment Annotations

Call the PdfAnnotationFacade.Remove() method to remove an annotation. The code sample below removes all file attachment annotations on the first page.

using DevExpress.Pdf;
using System.Linq;
//...
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Retrieve all file attachment annotations
    var fileAttachmentAnnotations = pageFacade.Annotations.Where
      (annotation => annotation.Type == PdfAnnotationType.FileAttachment).ToList();

    // Remove all annotations
    foreach (PdfFileAttachmentAnnotationFacade fileAttachment in fileAttachmentAnnotations)
    {
      fileAttachment.Remove();
    }
    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}

Inheritance

See Also