officefileapi-devexpress-dot-pdf-c933f1db.md
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
public class PdfFileAttachmentAnnotationFacade :
PdfMarkupAnnotationFacade
Public Class PdfFileAttachmentAnnotationFacade
Inherits PdfMarkupAnnotationFacade
The following members return PdfFileAttachmentAnnotationFacade objects:
The code sample below creates a 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");
}
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
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");
}
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
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");
}
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
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");
}
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
Object PdfAnnotationFacade PdfMarkupAnnotationFacade PdfFileAttachmentAnnotationFacade
See Also