Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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

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

#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.

View Example

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

#Inheritance

Object
PdfFileAttachment
See Also