Back to Devexpress

PdfDocumentProcessor.AttachFile(PdfFileAttachment) Method

officefileapi-devexpress-dot-pdf-dot-pdfdocumentprocessor-dot-attachfile-x28-devexpress-dot-pdf-dot-pdffileattachment-x29.md

latest4.9 KB
Original Source

PdfDocumentProcessor.AttachFile(PdfFileAttachment) Method

Attaches a file to the PDF document.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public void AttachFile(
    PdfFileAttachment attachment
)
vb
Public Sub AttachFile(
    attachment As PdfFileAttachment
)

Parameters

NameTypeDescription
attachmentPdfFileAttachment

A PdfFileAttachment object that contains settings to attach a file to the PDF document.

|

Remarks

Use this method to include an attachment to the PDF document using the necessary settings such as attachment data (PdfFileAttachment.Data), a file name (PdfFileAttachment.FileName), creation date (PdfFileAttachment.CreationDate), modification date (PdfFileAttachment.ModificationDate) and other settings.

Example

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

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

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.

pdf-document-api-attach-file-to-document/CS/AttachFile/Program.cs#L16

csharp
// Attach a file to the PDF document.
processor.AttachFile(new PdfFileAttachment() {
    CreationDate = DateTime.Now,

pdf-document-api-attach-file-to-document/VB/AttachFile/Program.vb#L13

vb
' Attach a file to the PDF document.
processor.AttachFile(New PdfFileAttachment() With {.CreationDate = Date.Now, .Description = "This is my attach file.", .FileName = "MyAttach.txt", .Data = File.ReadAllBytes("..\..\..\FileToAttach.txt"), .MimeType = "text/plain", .Relationship = PdfAssociatedFileRelationship.Supplement})
' The attached document.

See Also

PdfDocumentProcessor Class

PdfDocumentProcessor Members

DevExpress.Pdf Namespace