Back to Devexpress

PdfFileAttachmentAnnotationFacade Class

officefileapi-devexpress-dot-pdf-c933f1db.md

latest10.0 KB
Original Source

PdfFileAttachmentAnnotationFacade Class

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

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public class PdfFileAttachmentAnnotationFacade :
    PdfMarkupAnnotationFacade
vb
Public Class PdfFileAttachmentAnnotationFacade
    Inherits PdfMarkupAnnotationFacade

The following members return PdfFileAttachmentAnnotationFacade objects:

Remarks

Create File Attachment Annotations

The code sample below creates a file attachment annotation:

csharp
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");
}
vb
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Specify attachment data
  Dim attachment As New PdfFileAttachment()
  With {.CreationDate = Date.Now,
    .Description = "This is my attached file.",
    .FileName = "MyAttach.txt",
    .Data = File.ReadAllBytes("..\..\FileToAttach.txt")}

  ' Create a file attachment annotation
    Dim pdfFileAttachment As PdfFileAttachmentAnnotationFacade =
       pageFacade.AddFileAttachmentAnnotation(New PdfPoint(700,100), attachment,
         PdfFileAttachmentAnnotationIconName.PaperClip)
    pdfFileAttachment.Author = "Sabella Jaida"
    pdfFileAttachment.Subject = "Attachment"

  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

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.

csharp
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");
}
vb
Imports DevExpress.Pdf
Imports System.Linq
'...
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Retrieve all file attachment annotations
  Dim fileAttachmentAnnotations = pageFacade.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.FileAttachment)
  For Each fileAttachmentAnnotation As PdfFileAttachmentAnnotationFacade In fileAttachmentAnnotations
    ' Change annotation parameters
    fileAttachmentAnnotation.Color = New PdfRGBColor(0.36, 0.54, 0.66)
    fileAttachmentAnnotation.Author = "Tobias Rieper"
    fileAttachmentAnnotation.IconName = PdfFileAttachmentAnnotationIconName.Tag
  Next fileAttachmentAnnotation
  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Flatten File Attachment Annotations

Call one of the following methods to flatten an annotation:

MethodDescription
PdfDocumentFacade.FlattenAnnotationsFlattens document annotations.
PdfPageFacade.FlattenAnnotationsFlattens 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.

csharp
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");
}
vb
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Flatten annotations
  pageFacade.FlattenAnnotations(PdfAnnotationType.FileAttachment)

  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

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.

csharp
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");
}
vb
Imports DevExpress.Pdf
Imports System.Linq
'...
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Retrieve all file attachment annotations
  Dim fileAttachmentAnnotations = pageFacade.Annotations.Where
    (Function(annotation) annotation.Type = PdfAnnotationType.FileAttachment).ToList()

  ' Remove all annotations
  For Each fileAttachment As PdfFileAttachmentAnnotationFacade In fileAttachmentAnnotations
    fileAttachment.Remove()
  Next fileAttachment
  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

Inheritance

Object PdfAnnotationFacade PdfMarkupAnnotationFacade PdfFileAttachmentAnnotationFacade

See Also

PdfFileAttachmentAnnotationFacade Members

DevExpress.Pdf Namespace