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

Attachments in PDF Documents

  • 2 minutes to read

File attachments are represented by an instance of the PdfFileAttachment class. You can specify the attachment creation date, description, and file name using PdfFileAttachment.CreationDate, PdfFileAttachment.Description, and PdfFileAttachment.FileName properties. You also need to specify the file data for the attachment using the PdfFileAttachment.Data property.

If required, you can specify additional properties of a file attachment such as a file’s MIME type and relationship using PdfFileAttachment.MimeType, and PdfFileAttachment.Relationship properties.

To attach a file to a document, call the PdfDocumentProcessor.AttachFile method.

To get an attachment, use the PdfDocument.FileAttachments property.

To delete an attachment, call the PdfDocumentProcessor.DeleteAttachment method.

#Example

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