officefileapi-devexpress-dot-pdf-842a32ee.md
A file attached to a PDF document.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Core.dll
NuGet Package : DevExpress.Pdf.Core
public class PdfFileAttachment
Public Class PdfFileAttachment
The following members return PdfFileAttachment objects:
| Library | Related API Members |
|---|---|
| WinForms Controls | PdfFileAttachmentOpeningEventArgs.FileAttachment |
| WPF Controls | AttachmentOpeningEventArgs.Attachment |
| Office File API | PdfFileAttachmentAnnotationFacade.Attachment |
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 attached file.",
FileName = "MyAttach.txt",
Data = File.ReadAllBytes("..\\..\\..\\FileToAttach.txt"),
MimeType = "text/plain",
Relationship = PdfAssociatedFileRelationship.Supplement,
});
// The attached document.
processor.SaveDocument("..\\..\\Result.pdf");
}
Imports DevExpress.Pdf
Imports System
Imports System.IO
Shared Sub Main(ByVal args() As String)
Using processor As New PdfDocumentProcessor()
' Load a document.
processor.LoadDocument("..\..\Document.pdf")
' Attach a file to the PDF document.
processor.AttachFile(New PdfFileAttachment() With { _
.CreationDate = Date.Now, _
.Description = "This is my attached file.", _
.FileName = "MyAttach.txt", _
.Data = File.ReadAllBytes("..\..\FileToAttach.txt"), _
.MimeType = "text/plain",
.Relationship = PdfAssociatedFileRelationship.Supplement
})
' The attached document.
processor.SaveDocument("..\..\Result.pdf")
End Using
End Sub
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");
}
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
Object PdfFileAttachment
See Also