PdfFileAttachment Class
A file attached to a PDF document.
Namespace: DevExpress.Pdf
Assembly: DevExpress.Pdf.v24.2.Core.dll
NuGet Package: DevExpress.Pdf.Core
#Declaration
#Related API Members
The following members return PdfFileAttachment objects:
Library | Related API Members |
---|---|
Win |
Pdf |
WPF Controls | Attachment |
Office File API | Pdf |
#Remarks
#Example: Attach a File to the PDF Document
Pass the PdfFileAttachment object as the PdfDocumentProcessor.AttachFile(PdfFileAttachment) method parameter to attach a file to a PDF document.
using DevExpress.Pdf;
using System;
using System.IO;
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
// Load a document.
processor.LoadDocument("..\\..\\Document.pdf");
// Attach a file to the PDF document.
processor.AttachFile(new PdfFileAttachment() {
CreationDate = DateTime.Now,
Description = "This is my attach file.",
FileName = "MyAttach.txt",
Data = File.ReadAllBytes("..\\..\\FileToAttach.txt")
});
// The attached document.
processor.SaveDocument("..\\..\\Result.pdf");
}
#Example: Create a File Attachment Annotation
Pass the PdfFileAttachment object as the PdfPageFacade.AddFileAttachmentAnnotation() method parameter to create a file attachment annotation.
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");
}