Back to Devexpress

PdfFileAttachment Class

officefileapi-devexpress-dot-pdf-842a32ee.md

latest5.6 KB
Original Source

PdfFileAttachment Class

A file attached to a PDF document.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public class PdfFileAttachment
vb
Public Class PdfFileAttachment

The following members return PdfFileAttachment objects:

LibraryRelated API Members
WinForms ControlsPdfFileAttachmentOpeningEventArgs.FileAttachment
WPF ControlsAttachmentOpeningEventArgs.Attachment
Office File APIPdfFileAttachmentAnnotationFacade.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

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

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:

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

Inheritance

Object PdfFileAttachment

See Also

PdfFileAttachment Members

DevExpress.Pdf Namespace