.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

PdfFileAttachment Class

A file attached to a PDF document.

Namespace: DevExpress.Pdf

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

Declaration

public class PdfFileAttachment

The following members accept/return PdfFileAttachment objects:

Library Related API Members
WinForms Controls PdfFileAttachmentOpeningEventArgs.FileAttachment
WPF Controls AttachmentOpeningEventArgs.Attachment
Office File API PdfFileAttachmentAnnotationFacade.Attachment

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:

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");
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the PdfFileAttachment class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

Inheritance

Object
PdfFileAttachment
See Also